hid_host.c (b4c969508293980a60ef0b5378098d3cb8b366d0) hid_host.c (14618ebfef9875b25a069464851370b09f5b07fa)
1/*
2 * Copyright (C) 2014 BlueKitchen GmbH
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright

--- 1104 unchanged lines hidden (view full) ---

1113 connection->w4_set_protocol_response = true;
1114 l2cap_send(connection->control_cid, (uint8_t*) report, sizeof(report));
1115 break;
1116 }
1117 break;
1118
1119 case HID_HOST_W2_SEND_GET_REPORT:{
1120 uint8_t header = (HID_MESSAGE_TYPE_GET_REPORT << 4) | connection->report_type;
1/*
2 * Copyright (C) 2014 BlueKitchen GmbH
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright

--- 1104 unchanged lines hidden (view full) ---

1113 connection->w4_set_protocol_response = true;
1114 l2cap_send(connection->control_cid, (uint8_t*) report, sizeof(report));
1115 break;
1116 }
1117 break;
1118
1119 case HID_HOST_W2_SEND_GET_REPORT:{
1120 uint8_t header = (HID_MESSAGE_TYPE_GET_REPORT << 4) | connection->report_type;
1121 uint8_t report[] = {header, connection->report_id};
1121 uint8_t report[2];
1122 uint16_t pos = 0;
1123 report[pos++] = header;
1124 if (connection->report_id != HID_REPORT_ID_UNDEFINED){
1125 report[pos++] = (uint8_t) connection->report_id;
1126 }
1122
1123 connection->state = HID_HOST_W4_GET_REPORT_RESPONSE;
1127
1128 connection->state = HID_HOST_W4_GET_REPORT_RESPONSE;
1124 l2cap_send(connection->control_cid, (uint8_t*) report, sizeof(report));
1129 l2cap_send(connection->control_cid, (uint8_t*) report, pos);
1125 break;
1126 }
1127
1128 case HID_HOST_W2_SEND_SET_REPORT:{
1129 uint8_t header = (HID_MESSAGE_TYPE_SET_REPORT << 4) | connection->report_type;
1130 connection->state = HID_HOST_W4_SET_REPORT_RESPONSE;
1131
1132 l2cap_reserve_packet_buffer();
1133 uint8_t * out_buffer = l2cap_get_outgoing_buffer();
1130 break;
1131 }
1132
1133 case HID_HOST_W2_SEND_SET_REPORT:{
1134 uint8_t header = (HID_MESSAGE_TYPE_SET_REPORT << 4) | connection->report_type;
1135 connection->state = HID_HOST_W4_SET_REPORT_RESPONSE;
1136
1137 l2cap_reserve_packet_buffer();
1138 uint8_t * out_buffer = l2cap_get_outgoing_buffer();
1134 out_buffer[0] = header;
1135 out_buffer[1] = connection->report_id;
1136 (void)memcpy(out_buffer + 2, connection->report, connection->report_len);
1137 l2cap_send_prepared(connection->control_cid, connection->report_len + 2);
1139 uint16_t pos = 0;
1140 out_buffer[pos++] = header;
1141 if (connection->report_id != HID_REPORT_ID_UNDEFINED){
1142 out_buffer[pos++] = (uint8_t) connection->report_id;
1143 }
1144 (void)memcpy(&out_buffer[pos], connection->report, connection->report_len);
1145 pos += connection->report_len;
1146 l2cap_send_prepared(connection->control_cid, pos);
1138 break;
1139 }
1140
1141 case HID_HOST_W2_SEND_GET_PROTOCOL:{
1142 uint8_t header = (HID_MESSAGE_TYPE_GET_PROTOCOL << 4);
1143 uint8_t report[] = {header};
1144 connection->state = HID_HOST_W4_GET_PROTOCOL_RESPONSE;
1145 l2cap_send(connection->control_cid, (uint8_t*) report, sizeof(report));

--- 7 unchanged lines hidden (view full) ---

1153
1154 if (connection->interrupt_cid == l2cap_cid && connection->state == HID_HOST_W2_SEND_REPORT){
1155 connection->state = HID_HOST_CONNECTION_ESTABLISHED;
1156 // there is no response for this type of message
1157 uint8_t header = (HID_MESSAGE_TYPE_DATA << 4) | connection->report_type;
1158
1159 l2cap_reserve_packet_buffer();
1160 uint8_t * out_buffer = l2cap_get_outgoing_buffer();
1147 break;
1148 }
1149
1150 case HID_HOST_W2_SEND_GET_PROTOCOL:{
1151 uint8_t header = (HID_MESSAGE_TYPE_GET_PROTOCOL << 4);
1152 uint8_t report[] = {header};
1153 connection->state = HID_HOST_W4_GET_PROTOCOL_RESPONSE;
1154 l2cap_send(connection->control_cid, (uint8_t*) report, sizeof(report));

--- 7 unchanged lines hidden (view full) ---

1162
1163 if (connection->interrupt_cid == l2cap_cid && connection->state == HID_HOST_W2_SEND_REPORT){
1164 connection->state = HID_HOST_CONNECTION_ESTABLISHED;
1165 // there is no response for this type of message
1166 uint8_t header = (HID_MESSAGE_TYPE_DATA << 4) | connection->report_type;
1167
1168 l2cap_reserve_packet_buffer();
1169 uint8_t * out_buffer = l2cap_get_outgoing_buffer();
1161 out_buffer[0] = header;
1162 out_buffer[1] = connection->report_id;
1163 (void)memcpy(out_buffer + 2, connection->report, connection->report_len);
1164 l2cap_send_prepared(connection->interrupt_cid, connection->report_len + 2);
1170 uint16_t pos = 0;
1171 out_buffer[pos++] = header;
1172 if (connection->report_id != HID_REPORT_ID_UNDEFINED){
1173 out_buffer[pos++] = (uint8_t) connection->report_id;
1174 }
1175 (void)memcpy(&out_buffer[pos], connection->report, connection->report_len);
1176 pos += connection->report_len;
1177 l2cap_send_prepared(connection->interrupt_cid, pos);
1165 break;
1166 }
1167
1168 if (connection->control_tasks != 0){
1169 l2cap_request_can_send_now_event(connection->control_cid);
1170 }
1171 break;
1172 default:

--- 166 unchanged lines hidden (view full) ---

1339uint8_t hid_host_send_exit_suspend(uint16_t hid_cid){
1340 return hid_host_send_control_message(hid_cid, CONTROL_MESSAGE_BITMASK_EXIT_SUSPEND);
1341}
1342
1343uint8_t hid_host_send_virtual_cable_unplug(uint16_t hid_cid){
1344 return hid_host_send_control_message(hid_cid, CONTROL_MESSAGE_BITMASK_VIRTUAL_CABLE_UNPLUG);
1345}
1346
1178 break;
1179 }
1180
1181 if (connection->control_tasks != 0){
1182 l2cap_request_can_send_now_event(connection->control_cid);
1183 }
1184 break;
1185 default:

--- 166 unchanged lines hidden (view full) ---

1352uint8_t hid_host_send_exit_suspend(uint16_t hid_cid){
1353 return hid_host_send_control_message(hid_cid, CONTROL_MESSAGE_BITMASK_EXIT_SUSPEND);
1354}
1355
1356uint8_t hid_host_send_virtual_cable_unplug(uint16_t hid_cid){
1357 return hid_host_send_control_message(hid_cid, CONTROL_MESSAGE_BITMASK_VIRTUAL_CABLE_UNPLUG);
1358}
1359
1347uint8_t hid_host_send_get_report(uint16_t hid_cid, hid_report_type_t report_type, uint8_t report_id){
1360uint8_t hid_host_send_get_report(uint16_t hid_cid, hid_report_type_t report_type, uint16_t report_id){
1348 hid_host_connection_t * connection = hid_host_get_connection_for_hid_cid(hid_cid);
1349
1350 if (!connection || !connection->control_cid){
1351 return ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER;
1352 }
1353 if (connection->state != HID_HOST_CONNECTION_ESTABLISHED){
1354 return ERROR_CODE_COMMAND_DISALLOWED;
1355 }
1356
1357 connection->state = HID_HOST_W2_SEND_GET_REPORT;
1358 connection->report_type = report_type;
1359 connection->report_id = report_id;
1360
1361 l2cap_request_can_send_now_event(connection->control_cid);
1362 return ERROR_CODE_SUCCESS;
1363}
1364
1361 hid_host_connection_t * connection = hid_host_get_connection_for_hid_cid(hid_cid);
1362
1363 if (!connection || !connection->control_cid){
1364 return ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER;
1365 }
1366 if (connection->state != HID_HOST_CONNECTION_ESTABLISHED){
1367 return ERROR_CODE_COMMAND_DISALLOWED;
1368 }
1369
1370 connection->state = HID_HOST_W2_SEND_GET_REPORT;
1371 connection->report_type = report_type;
1372 connection->report_id = report_id;
1373
1374 l2cap_request_can_send_now_event(connection->control_cid);
1375 return ERROR_CODE_SUCCESS;
1376}
1377
1365uint8_t hid_host_send_set_report(uint16_t hid_cid, hid_report_type_t report_type, uint8_t report_id, const uint8_t * report, uint8_t report_len){
1378uint8_t hid_host_send_set_report(uint16_t hid_cid, hid_report_type_t report_type, uint16_t report_id, const uint8_t * report, uint8_t report_len){
1366 hid_host_connection_t * connection = hid_host_get_connection_for_hid_cid(hid_cid);
1367
1368 if (!connection || !connection->control_cid){
1369 return ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER;
1370 }
1371
1372 if (connection->state != HID_HOST_CONNECTION_ESTABLISHED){
1373 return ERROR_CODE_COMMAND_DISALLOWED;

--- 39 unchanged lines hidden (view full) ---

1413 connection->set_protocol = true;
1414 connection->requested_protocol_mode = protocol_mode;
1415
1416 l2cap_request_can_send_now_event(connection->control_cid);
1417 return ERROR_CODE_SUCCESS;
1418}
1419
1420
1379 hid_host_connection_t * connection = hid_host_get_connection_for_hid_cid(hid_cid);
1380
1381 if (!connection || !connection->control_cid){
1382 return ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER;
1383 }
1384
1385 if (connection->state != HID_HOST_CONNECTION_ESTABLISHED){
1386 return ERROR_CODE_COMMAND_DISALLOWED;

--- 39 unchanged lines hidden (view full) ---

1426 connection->set_protocol = true;
1427 connection->requested_protocol_mode = protocol_mode;
1428
1429 l2cap_request_can_send_now_event(connection->control_cid);
1430 return ERROR_CODE_SUCCESS;
1431}
1432
1433
1421uint8_t hid_host_send_report(uint16_t hid_cid, uint8_t report_id, const uint8_t * report, uint8_t report_len){
1434uint8_t hid_host_send_report(uint16_t hid_cid, uint16_t report_id, const uint8_t * report, uint8_t report_len){
1422 hid_host_connection_t * connection = hid_host_get_connection_for_hid_cid(hid_cid);
1423 if (!connection || !connection->control_cid || !connection->interrupt_cid) {
1424 return ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER;
1425 }
1426
1427 if (connection->state < HID_HOST_CONNECTION_ESTABLISHED) {
1428 return ERROR_CODE_COMMAND_DISALLOWED;
1429 }

--- 17 unchanged lines hidden ---
1435 hid_host_connection_t * connection = hid_host_get_connection_for_hid_cid(hid_cid);
1436 if (!connection || !connection->control_cid || !connection->interrupt_cid) {
1437 return ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER;
1438 }
1439
1440 if (connection->state < HID_HOST_CONNECTION_ESTABLISHED) {
1441 return ERROR_CODE_COMMAND_DISALLOWED;
1442 }

--- 17 unchanged lines hidden ---