Changeset 374 for asp3_tinet_ecnl_arm/trunk/btstack/src/l2cap.c
- Timestamp:
- Apr 5, 2019, 9:26:53 PM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
asp3_tinet_ecnl_arm/trunk/btstack/src/l2cap.c
r352 r374 135 135 event[1] = sizeof(event) - 2; 136 136 event[2] = status; 137 bt_flip_addr(&event[3], channel->address);138 bt_store_16(event, 9, channel->handle);139 bt_store_16(event, 11, channel->psm);140 bt_store_16(event, 13, channel->local_cid);141 bt_store_16(event, 15, channel->remote_cid);142 bt_store_16(event, 17, channel->local_mtu);143 bt_store_16(event, 19, channel->remote_mtu);144 bt_store_16(event, 21, channel->flush_timeout);137 reverse_bd_addr(channel->address, &event[3]); 138 little_endian_store_16(event, 9, channel->handle); 139 little_endian_store_16(event, 11, channel->psm); 140 little_endian_store_16(event, 13, channel->local_cid); 141 little_endian_store_16(event, 15, channel->remote_cid); 142 little_endian_store_16(event, 17, channel->local_mtu); 143 little_endian_store_16(event, 19, channel->remote_mtu); 144 little_endian_store_16(event, 21, channel->flush_timeout); 145 145 hci_dump_packet( HCI_EVENT_PACKET, 0, event, sizeof(event)); 146 146 l2cap_dispatch(channel, HCI_EVENT_PACKET, event, sizeof(event)); … … 152 152 event[0] = L2CAP_EVENT_CHANNEL_CLOSED; 153 153 event[1] = sizeof(event) - 2; 154 bt_store_16(event, 2, channel->local_cid);154 little_endian_store_16(event, 2, channel->local_cid); 155 155 hci_dump_packet( HCI_EVENT_PACKET, 0, event, sizeof(event)); 156 156 l2cap_dispatch(channel, HCI_EVENT_PACKET, event, sizeof(event)); … … 163 163 event[0] = L2CAP_EVENT_INCOMING_CONNECTION; 164 164 event[1] = sizeof(event) - 2; 165 bt_flip_addr(&event[2], channel->address);166 bt_store_16(event, 8, channel->handle);167 bt_store_16(event, 10, channel->psm);168 bt_store_16(event, 12, channel->local_cid);169 bt_store_16(event, 14, channel->remote_cid);165 reverse_bd_addr(channel->address, &event[2]); 166 little_endian_store_16(event, 8, channel->handle); 167 little_endian_store_16(event, 10, channel->psm); 168 little_endian_store_16(event, 12, channel->local_cid); 169 little_endian_store_16(event, 14, channel->remote_cid); 170 170 hci_dump_packet( HCI_EVENT_PACKET, 0, event, sizeof(event)); 171 171 l2cap_dispatch(channel, HCI_EVENT_PACKET, event, sizeof(event)); … … 176 176 event[0] = L2CAP_EVENT_CONNECTION_PARAMETER_UPDATE_RESPONSE; 177 177 event[1] = 4; 178 bt_store_16(event, 2, handle);179 bt_store_16(event, 4, result);178 little_endian_store_16(event, 2, handle); 179 little_endian_store_16(event, 4, result); 180 180 hci_dump_packet( HCI_EVENT_PACKET, 0, event, sizeof(event)); 181 181 (*packet_handler)(NULL, HCI_EVENT_PACKET, 0, event, sizeof(event)); … … 188 188 event[1] = sizeof(event) - 2; 189 189 event[2] = status; 190 bt_store_16(event, 3, psm);190 little_endian_store_16(event, 3, psm); 191 191 hci_dump_packet( HCI_EVENT_PACKET, 0, event, sizeof(event)); 192 192 (*packet_handler)(connection, HCI_EVENT_PACKET, 0, event, sizeof(event)); … … 201 201 event[0] = L2CAP_EVENT_CREDITS; 202 202 event[1] = sizeof(event) - 2; 203 bt_store_16(event, 2, channel->local_cid);203 little_endian_store_16(event, 2, channel->local_cid); 204 204 event[4] = credits; 205 205 hci_dump_packet( HCI_EVENT_PACKET, 0, event, sizeof(event)); … … 412 412 413 413 // 0 - Connection handle : PB=pb : BC=00 414 bt_store_16(acl_buffer, 0, channel->handle | (pb << 12) | (0 << 14));414 little_endian_store_16(acl_buffer, 0, channel->handle | (pb << 12) | (0 << 14)); 415 415 // 2 - ACL length 416 bt_store_16(acl_buffer, 2, len + 4);416 little_endian_store_16(acl_buffer, 2, len + 4); 417 417 // 4 - L2CAP packet length 418 bt_store_16(acl_buffer, 4, len + 0);418 little_endian_store_16(acl_buffer, 4, len + 0); 419 419 // 6 - L2CAP channel DEST 420 bt_store_16(acl_buffer, 6, channel->remote_cid);420 little_endian_store_16(acl_buffer, 6, channel->remote_cid); 421 421 // send 422 422 err = hci_send_acl_packet_buffer(len+8); … … 449 449 450 450 // 0 - Connection handle : PB=pb : BC=00 451 bt_store_16(acl_buffer, 0, handle | (pb << 12) | (0 << 14));451 little_endian_store_16(acl_buffer, 0, handle | (pb << 12) | (0 << 14)); 452 452 // 2 - ACL length 453 bt_store_16(acl_buffer, 2, len + 4);453 little_endian_store_16(acl_buffer, 2, len + 4); 454 454 // 4 - L2CAP packet length 455 bt_store_16(acl_buffer, 4, len + 0);455 little_endian_store_16(acl_buffer, 4, len + 0); 456 456 // 6 - L2CAP channel DEST 457 bt_store_16(acl_buffer, 6, cid);457 little_endian_store_16(acl_buffer, 6, cid); 458 458 // send 459 459 err = hci_send_acl_packet_buffer(len+8); … … 665 665 config_options[0] = 1; // MTU 666 666 config_options[1] = 2; // len param 667 bt_store_16( (uint8_t*)&config_options, 2, channel->remote_mtu);667 little_endian_store_16( (uint8_t*)&config_options, 2, channel->remote_mtu); 668 668 l2cap_send_signaling_packet(channel->handle, CONFIGURE_RESPONSE, channel->remote_sig_id, channel->remote_cid, flags, 0, 4, &config_options); 669 669 channelStateVarClearFlag(channel,L2CAP_CHANNEL_STATE_VAR_SEND_CONF_RSP_MTU); … … 679 679 config_options[0] = 1; // MTU 680 680 config_options[1] = 2; // len param 681 bt_store_16( (uint8_t*)&config_options, 2, channel->local_mtu);681 little_endian_store_16( (uint8_t*)&config_options, 2, channel->local_mtu); 682 682 l2cap_send_signaling_packet(channel->handle, CONFIGURE_REQUEST, channel->local_sig_id, channel->remote_cid, 0, 4, &config_options); 683 683 l2cap_start_rtx(channel); … … 893 893 // handle connection complete events 894 894 case HCI_EVENT_CONNECTION_COMPLETE: 895 bt_flip_addr(address, &packet[5]);895 reverse_bd_addr(&packet[5], address); 896 896 if (packet[2] == 0){ 897 handle = READ_BT_16(packet, 3);897 handle = little_endian_read_16(packet, 3); 898 898 l2cap_handle_connection_success_for_addr(address, handle); 899 899 } else { … … 904 904 // handle successful create connection cancel command 905 905 case HCI_EVENT_COMMAND_COMPLETE: 906 if ( COMMAND_COMPLETE_EVENT(packet, hci_create_connection_cancel) ) {906 if ( HCI_EVENT_IS_COMMAND_COMPLETE(packet, hci_create_connection_cancel) ) { 907 907 if (packet[5] == 0){ 908 bt_flip_addr(address, &packet[6]);908 reverse_bd_addr(&packet[6], address); 909 909 // CONNECTION TERMINATED BY LOCAL HOST (0X16) 910 910 l2cap_handle_connection_failed_for_addr(address, 0x16); … … 921 921 case HCI_EVENT_DISCONNECTION_COMPLETE: 922 922 // send l2cap disconnect events for all channels on this handle and free them 923 handle = READ_BT_16(packet, 3);923 handle = little_endian_read_16(packet, 3); 924 924 linked_list_iterator_init(&it, &l2cap_channels); 925 925 while (linked_list_iterator_has_next(&it)){ … … 940 940 // HCI Connection Timeouts 941 941 case L2CAP_EVENT_TIMEOUT_CHECK: 942 handle = READ_BT_16(packet, 2);942 handle = little_endian_read_16(packet, 2); 943 943 if (hci_authentication_active_for_handle(handle)) break; 944 944 hci_con_used = 0; … … 971 971 972 972 case HCI_EVENT_READ_REMOTE_SUPPORTED_FEATURES_COMPLETE: 973 handle = READ_BT_16(packet, 3);973 handle = little_endian_read_16(packet, 3); 974 974 linked_list_iterator_init(&it, &l2cap_channels); 975 975 while (linked_list_iterator_has_next(&it)){ … … 982 982 983 983 case GAP_SECURITY_LEVEL: 984 handle = READ_BT_16(packet, 2);984 handle = little_endian_read_16(packet, 2); 985 985 log_info("l2cap - security level update"); 986 986 linked_list_iterator_init(&it, &l2cap_channels); … … 1163 1163 channel->remote_sig_id = command[L2CAP_SIGNALING_COMMAND_SIGID_OFFSET]; 1164 1164 1165 flags = READ_BT_16(command, 6);1165 flags = little_endian_read_16(command, 6); 1166 1166 if (flags & 1) { 1167 1167 channelStateVarSetFlag(channel, L2CAP_CHANNEL_STATE_VAR_SEND_CONF_RSP_CONT); … … 1169 1169 1170 1170 // accept the other's configuration options 1171 end_pos = 4 + READ_BT_16(command, L2CAP_SIGNALING_COMMAND_LENGTH_OFFSET);1171 end_pos = 4 + little_endian_read_16(command, L2CAP_SIGNALING_COMMAND_LENGTH_OFFSET); 1172 1172 pos = 8; 1173 1173 while (pos < end_pos){ … … 1180 1180 // MTU { type(8): 1, len(8):2, MTU(16) } 1181 1181 if (option_type == 1 && length == 2){ 1182 channel->remote_mtu = READ_BT_16(command, pos);1182 channel->remote_mtu = little_endian_read_16(command, pos); 1183 1183 // log_info("l2cap cid 0x%02x, remote mtu %u", channel->local_cid, channel->remote_mtu); 1184 1184 channelStateVarSetFlag(channel, L2CAP_CHANNEL_STATE_VAR_SEND_CONF_RSP_MTU); … … 1186 1186 // Flush timeout { type(8):2, len(8): 2, Flush Timeout(16)} 1187 1187 if (option_type == 2 && length == 2){ 1188 channel->flush_timeout = READ_BT_16(command, pos);1188 channel->flush_timeout = little_endian_read_16(command, pos); 1189 1189 } 1190 1190 // check for unknown options … … 1237 1237 case CONNECTION_RESPONSE: 1238 1238 l2cap_stop_rtx(channel); 1239 result = READ_BT_16 (command, L2CAP_SIGNALING_COMMAND_DATA_OFFSET+4);1239 result = little_endian_read_16 (command, L2CAP_SIGNALING_COMMAND_DATA_OFFSET+4); 1240 1240 switch (result) { 1241 1241 case 0: 1242 1242 // successful connection 1243 channel->remote_cid = READ_BT_16(command, L2CAP_SIGNALING_COMMAND_DATA_OFFSET);1243 channel->remote_cid = little_endian_read_16(command, L2CAP_SIGNALING_COMMAND_DATA_OFFSET); 1244 1244 channel->state = L2CAP_STATE_CONFIG; 1245 1245 channelStateVarSetFlag(channel, L2CAP_CHANNEL_STATE_VAR_SEND_CONF_REQ); … … 1274 1274 1275 1275 case L2CAP_STATE_CONFIG: 1276 result = READ_BT_16 (command, L2CAP_SIGNALING_COMMAND_DATA_OFFSET+4);1276 result = little_endian_read_16 (command, L2CAP_SIGNALING_COMMAND_DATA_OFFSET+4); 1277 1277 switch (code) { 1278 1278 case CONFIGURE_REQUEST: … … 1353 1353 1354 1354 case CONNECTION_REQUEST: { 1355 uint16_t psm = READ_BT_16(command, L2CAP_SIGNALING_COMMAND_DATA_OFFSET);1356 uint16_t source_cid = READ_BT_16(command, L2CAP_SIGNALING_COMMAND_DATA_OFFSET+2);1355 uint16_t psm = little_endian_read_16(command, L2CAP_SIGNALING_COMMAND_DATA_OFFSET); 1356 uint16_t source_cid = little_endian_read_16(command, L2CAP_SIGNALING_COMMAND_DATA_OFFSET+2); 1357 1357 l2cap_handle_connection_request(handle, sig_id, psm, source_cid); 1358 1358 return; … … 1364 1364 1365 1365 case INFORMATION_REQUEST: { 1366 uint16_t infoType = READ_BT_16(command, L2CAP_SIGNALING_COMMAND_DATA_OFFSET);1366 uint16_t infoType = little_endian_read_16(command, L2CAP_SIGNALING_COMMAND_DATA_OFFSET); 1367 1367 l2cap_register_signaling_response(handle, code, sig_id, infoType); 1368 1368 return; … … 1375 1375 1376 1376 // Get potential destination CID 1377 dest_cid = READ_BT_16(command, L2CAP_SIGNALING_COMMAND_DATA_OFFSET);1377 dest_cid = little_endian_read_16(command, L2CAP_SIGNALING_COMMAND_DATA_OFFSET); 1378 1378 1379 1379 // Find channel for this sig_id and connection handle … … 1415 1415 1416 1416 // increment command_offset 1417 command_offset += L2CAP_SIGNALING_COMMAND_DATA_OFFSET + READ_BT_16(packet, command_offset + L2CAP_SIGNALING_COMMAND_LENGTH_OFFSET);1417 command_offset += L2CAP_SIGNALING_COMMAND_DATA_OFFSET + little_endian_read_16(packet, command_offset + L2CAP_SIGNALING_COMMAND_LENGTH_OFFSET); 1418 1418 } 1419 1419 break; … … 1435 1435 switch (packet[8]){ 1436 1436 case CONNECTION_PARAMETER_UPDATE_RESPONSE: { 1437 uint16_t result = READ_BT_16(packet, 12);1437 uint16_t result = little_endian_read_16(packet, 12); 1438 1438 l2cap_emit_connection_parameter_update_response(handle, result); 1439 1439 break; … … 1450 1450 int update_parameter = 1; 1451 1451 le_connection_parameter_range_t existing_range = gap_le_get_connection_parameter_range(); 1452 uint16_t le_conn_interval_min = READ_BT_16(packet,12);1453 uint16_t le_conn_interval_max = READ_BT_16(packet,14);1454 uint16_t le_conn_latency = READ_BT_16(packet,16);1455 uint16_t le_supervision_timeout = READ_BT_16(packet,18);1452 uint16_t le_conn_interval_min = little_endian_read_16(packet,12); 1453 uint16_t le_conn_interval_max = little_endian_read_16(packet,14); 1454 uint16_t le_conn_latency = little_endian_read_16(packet,16); 1455 uint16_t le_supervision_timeout = little_endian_read_16(packet,18); 1456 1456 1457 1457 if (le_conn_interval_min < existing_range.le_conn_interval_min) update_parameter = 0;
Note:
See TracChangeset
for help on using the changeset viewer.