FreeBSD/usr.sbin/bluetooth/bthidd/kbd.c
/*
 * Process status change from vkbd(4)
 */
Process status change from vkbd(4)
Process status change from vkbd ( 4 )
int32_t
kbd_status_changed(bthid_session_p s, uint8_t *data, int32_t len)
{
	vkbd_status_t	st;
	uint8_t		found, report_id;
	hid_device_p	hid_device;
	hid_data_t	d;
	hid_item_t	h;
	assert(s != NULL);
	assert(len == sizeof(vkbd_status_t));
	memcpy(&st, data, sizeof(st));
	found = 0;
	report_id = NO_REPORT_ID;
	hid_device = get_hid_device(&s->bdaddr);
	assert(hid_device != NULL);
	data[0] = 0xa2; 
	data[1] = 0x00;
	data[2] = 0x00;
	for (d = hid_start_parse(hid_device->desc, 1 << hid_output, -1);
	     hid_get_item(d, &h) > 0; ) {
		if (HID_PAGE(h.usage) == HUP_LEDS) {
			found++;
			if (report_id == NO_REPORT_ID)
				report_id = h.report_ID;
			else if (h.report_ID != report_id)
				syslog(LOG_WARNING, "Output HID report IDs " \
					"for %s do not match: %d vs. %d. " \
					"Please report",
					bt_ntoa(&s->bdaddr, NULL),
					h.report_ID, report_id);
			switch(HID_USAGE(h.usage)) {
			case 0x01: 
				if (st.leds & LED_NUM)
					hid_set_data(&data[1], &h, 1);
				break;
			case 0x02: 
				if (st.leds & LED_CAP)
					hid_set_data(&data[1], &h, 1);
				break;
			case 0x03: 
				if (st.leds & LED_SCR)
					hid_set_data(&data[1], &h, 1);
				break;
			}
		}
	}
	hid_end_parse(d);
	if (found)
		write(s->intr, data, (report_id != NO_REPORT_ID) ? 3 : 2);
	return (0);
}
int32_t kbd_status_changed ( bthid_session_p s , uint8_t * data , int32_t len ) { vkbd_status_t st ; uint8_t found , report_id ; hid_device_p hid_device ; hid_data_t d ; hid_item_t h ; assert ( s != NULL ) ; assert ( len == sizeof ( vkbd_status_t ) ) ; memcpy ( & st , data , sizeof ( st ) ) ; found = 0 ; report_id = NO_REPORT_ID ; hid_device = get_hid_device ( & s -> bdaddr ) ; assert ( hid_device != NULL ) ; data [ 0 ] = 0xa2 ; data [ 1 ] = 0x00 ; data [ 2 ] = 0x00 ; for ( d = hid_start_parse ( hid_device -> desc , 1 << hid_output , -1 ) ; hid_get_item ( d , & h ) > 0 ; ) { if ( HID_PAGE ( h . usage ) == HUP_LEDS ) { found ++ ; if ( report_id == NO_REPORT_ID ) report_id = h . report_ID ; else if ( h . report_ID != report_id ) syslog ( LOG_WARNING , " " " " " " , bt_ntoa ( & s -> bdaddr , NULL ) , h . report_ID , report_id ) ; switch ( HID_USAGE ( h . usage ) ) { case 0x01 : if ( st . leds & LED_NUM ) hid_set_data ( & data [ 1 ] , & h , 1 ) ; break ; case 0x02 : if ( st . leds & LED_CAP ) hid_set_data ( & data [ 1 ] , & h , 1 ) ; break ; case 0x03 : if ( st . leds & LED_SCR ) hid_set_data ( & data [ 1 ] , & h , 1 ) ; break ; } } } hid_end_parse ( d ) ; if ( found ) write ( s -> intr , data , ( report_id != NO_REPORT_ID ) ? 3 : 2 ) ; return ( 0 ) ; }
Process status change from vkbd(4)
Process status change from vkbd ( 4 )
/* DATA output (HID output report) */ /* Num Lock LED */ /* Caps Lock LED */ /* Scroll Lock LED */ /* XXX add other LEDs ? */