Index: asp3_tinet_ecnl_rx/trunk/btstack/src/l2cap.c
===================================================================
--- asp3_tinet_ecnl_rx/trunk/btstack/src/l2cap.c	(revision 337)
+++ asp3_tinet_ecnl_rx/trunk/btstack/src/l2cap.c	(revision 374)
@@ -135,12 +135,12 @@
     event[1] = sizeof(event) - 2;
     event[2] = status;
-    bt_flip_addr(&event[3], channel->address);
-    bt_store_16(event,  9, channel->handle);
-    bt_store_16(event, 11, channel->psm);
-    bt_store_16(event, 13, channel->local_cid);
-    bt_store_16(event, 15, channel->remote_cid);
-    bt_store_16(event, 17, channel->local_mtu);
-    bt_store_16(event, 19, channel->remote_mtu);
-    bt_store_16(event, 21, channel->flush_timeout);
+    reverse_bd_addr(channel->address, &event[3]);
+    little_endian_store_16(event,  9, channel->handle);
+    little_endian_store_16(event, 11, channel->psm);
+    little_endian_store_16(event, 13, channel->local_cid);
+    little_endian_store_16(event, 15, channel->remote_cid);
+    little_endian_store_16(event, 17, channel->local_mtu);
+    little_endian_store_16(event, 19, channel->remote_mtu);
+    little_endian_store_16(event, 21, channel->flush_timeout);
     hci_dump_packet( HCI_EVENT_PACKET, 0, event, sizeof(event));
     l2cap_dispatch(channel, HCI_EVENT_PACKET, event, sizeof(event));
@@ -152,5 +152,5 @@
     event[0] = L2CAP_EVENT_CHANNEL_CLOSED;
     event[1] = sizeof(event) - 2;
-    bt_store_16(event, 2, channel->local_cid);
+    little_endian_store_16(event, 2, channel->local_cid);
     hci_dump_packet( HCI_EVENT_PACKET, 0, event, sizeof(event));
     l2cap_dispatch(channel, HCI_EVENT_PACKET, event, sizeof(event));
@@ -163,9 +163,9 @@
     event[0] = L2CAP_EVENT_INCOMING_CONNECTION;
     event[1] = sizeof(event) - 2;
-    bt_flip_addr(&event[2], channel->address);
-    bt_store_16(event,  8, channel->handle);
-    bt_store_16(event, 10, channel->psm);
-    bt_store_16(event, 12, channel->local_cid);
-    bt_store_16(event, 14, channel->remote_cid);
+    reverse_bd_addr(channel->address, &event[2]);
+    little_endian_store_16(event,  8, channel->handle);
+    little_endian_store_16(event, 10, channel->psm);
+    little_endian_store_16(event, 12, channel->local_cid);
+    little_endian_store_16(event, 14, channel->remote_cid);
     hci_dump_packet( HCI_EVENT_PACKET, 0, event, sizeof(event));
     l2cap_dispatch(channel, HCI_EVENT_PACKET, event, sizeof(event));
@@ -176,6 +176,6 @@
     event[0] = L2CAP_EVENT_CONNECTION_PARAMETER_UPDATE_RESPONSE;
     event[1] = 4;
-    bt_store_16(event, 2, handle);
-    bt_store_16(event, 4, result);
+    little_endian_store_16(event, 2, handle);
+    little_endian_store_16(event, 4, result);
     hci_dump_packet( HCI_EVENT_PACKET, 0, event, sizeof(event));
     (*packet_handler)(NULL, HCI_EVENT_PACKET, 0, event, sizeof(event));
@@ -188,5 +188,5 @@
     event[1] = sizeof(event) - 2;
     event[2] = status;
-    bt_store_16(event, 3, psm);
+    little_endian_store_16(event, 3, psm);
     hci_dump_packet( HCI_EVENT_PACKET, 0, event, sizeof(event));
     (*packet_handler)(connection, HCI_EVENT_PACKET, 0, event, sizeof(event));
@@ -201,5 +201,5 @@
     event[0] = L2CAP_EVENT_CREDITS;
     event[1] = sizeof(event) - 2;
-    bt_store_16(event, 2, channel->local_cid);
+    little_endian_store_16(event, 2, channel->local_cid);
     event[4] = credits;
     hci_dump_packet( HCI_EVENT_PACKET, 0, event, sizeof(event));
@@ -412,11 +412,11 @@
 
     // 0 - Connection handle : PB=pb : BC=00
-    bt_store_16(acl_buffer, 0, channel->handle | (pb << 12) | (0 << 14));
+    little_endian_store_16(acl_buffer, 0, channel->handle | (pb << 12) | (0 << 14));
     // 2 - ACL length
-    bt_store_16(acl_buffer, 2,  len + 4);
+    little_endian_store_16(acl_buffer, 2,  len + 4);
     // 4 - L2CAP packet length
-    bt_store_16(acl_buffer, 4,  len + 0);
+    little_endian_store_16(acl_buffer, 4,  len + 0);
     // 6 - L2CAP channel DEST
-    bt_store_16(acl_buffer, 6, channel->remote_cid);
+    little_endian_store_16(acl_buffer, 6, channel->remote_cid);
     // send
     err = hci_send_acl_packet_buffer(len+8);
@@ -449,11 +449,11 @@
 
     // 0 - Connection handle : PB=pb : BC=00
-    bt_store_16(acl_buffer, 0, handle | (pb << 12) | (0 << 14));
+    little_endian_store_16(acl_buffer, 0, handle | (pb << 12) | (0 << 14));
     // 2 - ACL length
-    bt_store_16(acl_buffer, 2,  len + 4);
+    little_endian_store_16(acl_buffer, 2,  len + 4);
     // 4 - L2CAP packet length
-    bt_store_16(acl_buffer, 4,  len + 0);
+    little_endian_store_16(acl_buffer, 4,  len + 0);
     // 6 - L2CAP channel DEST
-    bt_store_16(acl_buffer, 6, cid);
+    little_endian_store_16(acl_buffer, 6, cid);
     // send
     err = hci_send_acl_packet_buffer(len+8);
@@ -665,5 +665,5 @@
                         config_options[0] = 1; // MTU
                         config_options[1] = 2; // len param
-                        bt_store_16( (uint8_t*)&config_options, 2, channel->remote_mtu);
+                        little_endian_store_16( (uint8_t*)&config_options, 2, channel->remote_mtu);
                         l2cap_send_signaling_packet(channel->handle, CONFIGURE_RESPONSE, channel->remote_sig_id, channel->remote_cid, flags, 0, 4, &config_options);
                         channelStateVarClearFlag(channel,L2CAP_CHANNEL_STATE_VAR_SEND_CONF_RSP_MTU);
@@ -679,5 +679,5 @@
                     config_options[0] = 1; // MTU
                     config_options[1] = 2; // len param
-                    bt_store_16( (uint8_t*)&config_options, 2, channel->local_mtu);
+                    little_endian_store_16( (uint8_t*)&config_options, 2, channel->local_mtu);
                     l2cap_send_signaling_packet(channel->handle, CONFIGURE_REQUEST, channel->local_sig_id, channel->remote_cid, 0, 4, &config_options);
                     l2cap_start_rtx(channel);
@@ -893,7 +893,7 @@
         // handle connection complete events
         case HCI_EVENT_CONNECTION_COMPLETE:
-            bt_flip_addr(address, &packet[5]);
+            reverse_bd_addr(&packet[5], address);
             if (packet[2] == 0){
-                handle = READ_BT_16(packet, 3);
+                handle = little_endian_read_16(packet, 3);
                 l2cap_handle_connection_success_for_addr(address, handle);
             } else {
@@ -904,7 +904,7 @@
         // handle successful create connection cancel command
         case HCI_EVENT_COMMAND_COMPLETE:
-            if ( COMMAND_COMPLETE_EVENT(packet, hci_create_connection_cancel) ) {
+            if ( HCI_EVENT_IS_COMMAND_COMPLETE(packet, hci_create_connection_cancel) ) {
                 if (packet[5] == 0){
-                    bt_flip_addr(address, &packet[6]);
+                    reverse_bd_addr(&packet[6], address);
                     // CONNECTION TERMINATED BY LOCAL HOST (0X16)
                     l2cap_handle_connection_failed_for_addr(address, 0x16);
@@ -921,5 +921,5 @@
         case HCI_EVENT_DISCONNECTION_COMPLETE:
             // send l2cap disconnect events for all channels on this handle and free them
-            handle = READ_BT_16(packet, 3);
+            handle = little_endian_read_16(packet, 3);
             linked_list_iterator_init(&it, &l2cap_channels);
             while (linked_list_iterator_has_next(&it)){
@@ -940,5 +940,5 @@
         // HCI Connection Timeouts
         case L2CAP_EVENT_TIMEOUT_CHECK:
-            handle = READ_BT_16(packet, 2);
+            handle = little_endian_read_16(packet, 2);
             if (hci_authentication_active_for_handle(handle)) break;
             hci_con_used = 0;
@@ -971,5 +971,5 @@
 
         case HCI_EVENT_READ_REMOTE_SUPPORTED_FEATURES_COMPLETE:
-            handle = READ_BT_16(packet, 3);
+            handle = little_endian_read_16(packet, 3);
             linked_list_iterator_init(&it, &l2cap_channels);
             while (linked_list_iterator_has_next(&it)){
@@ -982,5 +982,5 @@
 
         case GAP_SECURITY_LEVEL:
-            handle = READ_BT_16(packet, 2);
+            handle = little_endian_read_16(packet, 2);
             log_info("l2cap - security level update");
             linked_list_iterator_init(&it, &l2cap_channels);
@@ -1163,5 +1163,5 @@
     channel->remote_sig_id = command[L2CAP_SIGNALING_COMMAND_SIGID_OFFSET];
 
-    flags = READ_BT_16(command, 6);
+    flags = little_endian_read_16(command, 6);
     if (flags & 1) {
         channelStateVarSetFlag(channel, L2CAP_CHANNEL_STATE_VAR_SEND_CONF_RSP_CONT);
@@ -1169,5 +1169,5 @@
 
     // accept the other's configuration options
-    end_pos = 4 + READ_BT_16(command, L2CAP_SIGNALING_COMMAND_LENGTH_OFFSET);
+    end_pos = 4 + little_endian_read_16(command, L2CAP_SIGNALING_COMMAND_LENGTH_OFFSET);
     pos     = 8;
     while (pos < end_pos){
@@ -1180,5 +1180,5 @@
         // MTU { type(8): 1, len(8):2, MTU(16) }
         if (option_type == 1 && length == 2){
-            channel->remote_mtu = READ_BT_16(command, pos);
+            channel->remote_mtu = little_endian_read_16(command, pos);
             // log_info("l2cap cid 0x%02x, remote mtu %u", channel->local_cid, channel->remote_mtu);
             channelStateVarSetFlag(channel, L2CAP_CHANNEL_STATE_VAR_SEND_CONF_RSP_MTU);
@@ -1186,5 +1186,5 @@
         // Flush timeout { type(8):2, len(8): 2, Flush Timeout(16)}
         if (option_type == 2 && length == 2){
-            channel->flush_timeout = READ_BT_16(command, pos);
+            channel->flush_timeout = little_endian_read_16(command, pos);
         }
         // check for unknown options
@@ -1237,9 +1237,9 @@
                 case CONNECTION_RESPONSE:
                     l2cap_stop_rtx(channel);
-                    result = READ_BT_16 (command, L2CAP_SIGNALING_COMMAND_DATA_OFFSET+4);
+                    result = little_endian_read_16 (command, L2CAP_SIGNALING_COMMAND_DATA_OFFSET+4);
                     switch (result) {
                         case 0:
                             // successful connection
-                            channel->remote_cid = READ_BT_16(command, L2CAP_SIGNALING_COMMAND_DATA_OFFSET);
+                            channel->remote_cid = little_endian_read_16(command, L2CAP_SIGNALING_COMMAND_DATA_OFFSET);
                             channel->state = L2CAP_STATE_CONFIG;
                             channelStateVarSetFlag(channel, L2CAP_CHANNEL_STATE_VAR_SEND_CONF_REQ);
@@ -1274,5 +1274,5 @@
 
         case L2CAP_STATE_CONFIG:
-            result = READ_BT_16 (command, L2CAP_SIGNALING_COMMAND_DATA_OFFSET+4);
+            result = little_endian_read_16 (command, L2CAP_SIGNALING_COMMAND_DATA_OFFSET+4);
             switch (code) {
                 case CONFIGURE_REQUEST:
@@ -1353,6 +1353,6 @@
 
         case CONNECTION_REQUEST: {
-            uint16_t psm =        READ_BT_16(command, L2CAP_SIGNALING_COMMAND_DATA_OFFSET);
-            uint16_t source_cid = READ_BT_16(command, L2CAP_SIGNALING_COMMAND_DATA_OFFSET+2);
+            uint16_t psm =        little_endian_read_16(command, L2CAP_SIGNALING_COMMAND_DATA_OFFSET);
+            uint16_t source_cid = little_endian_read_16(command, L2CAP_SIGNALING_COMMAND_DATA_OFFSET+2);
             l2cap_handle_connection_request(handle, sig_id, psm, source_cid);
             return;
@@ -1364,5 +1364,5 @@
 
         case INFORMATION_REQUEST: {
-            uint16_t infoType = READ_BT_16(command, L2CAP_SIGNALING_COMMAND_DATA_OFFSET);
+            uint16_t infoType = little_endian_read_16(command, L2CAP_SIGNALING_COMMAND_DATA_OFFSET);
             l2cap_register_signaling_response(handle, code, sig_id, infoType);
             return;
@@ -1375,5 +1375,5 @@
     
     // Get potential destination CID
-    dest_cid = READ_BT_16(command, L2CAP_SIGNALING_COMMAND_DATA_OFFSET);
+    dest_cid = little_endian_read_16(command, L2CAP_SIGNALING_COMMAND_DATA_OFFSET);
 
     // Find channel for this sig_id and connection handle
@@ -1415,5 +1415,5 @@
 
                 // increment command_offset
-                command_offset += L2CAP_SIGNALING_COMMAND_DATA_OFFSET + READ_BT_16(packet, command_offset + L2CAP_SIGNALING_COMMAND_LENGTH_OFFSET);
+                command_offset += L2CAP_SIGNALING_COMMAND_DATA_OFFSET + little_endian_read_16(packet, command_offset + L2CAP_SIGNALING_COMMAND_LENGTH_OFFSET);
             }
             break;
@@ -1435,5 +1435,5 @@
             switch (packet[8]){
                 case CONNECTION_PARAMETER_UPDATE_RESPONSE: {
-                    uint16_t result = READ_BT_16(packet, 12);
+                    uint16_t result = little_endian_read_16(packet, 12);
                     l2cap_emit_connection_parameter_update_response(handle, result);
                     break;
@@ -1450,8 +1450,8 @@
                         int update_parameter = 1;
                         le_connection_parameter_range_t existing_range = gap_le_get_connection_parameter_range();
-                        uint16_t le_conn_interval_min = READ_BT_16(packet,12);
-                        uint16_t le_conn_interval_max = READ_BT_16(packet,14);
-                        uint16_t le_conn_latency = READ_BT_16(packet,16);
-                        uint16_t le_supervision_timeout = READ_BT_16(packet,18);
+                        uint16_t le_conn_interval_min = little_endian_read_16(packet,12);
+                        uint16_t le_conn_interval_max = little_endian_read_16(packet,14);
+                        uint16_t le_conn_latency = little_endian_read_16(packet,16);
+                        uint16_t le_supervision_timeout = little_endian_read_16(packet,18);
 
                         if (le_conn_interval_min < existing_range.le_conn_interval_min) update_parameter = 0;
