Ignore:
Timestamp:
Apr 5, 2019, 9:26:53 PM (5 years ago)
Author:
coas-nagasima
Message:

mbed関連を更新
シリアルドライバをmbedのHALを使うよう変更
ファイルディスクリプタの処理を更新

File:
1 edited

Legend:

Unmodified
Added
Removed
  • asp3_tinet_ecnl_arm/trunk/btstack/src/l2cap.c

    r352 r374  
    135135    event[1] = sizeof(event) - 2;
    136136    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);
    145145    hci_dump_packet( HCI_EVENT_PACKET, 0, event, sizeof(event));
    146146    l2cap_dispatch(channel, HCI_EVENT_PACKET, event, sizeof(event));
     
    152152    event[0] = L2CAP_EVENT_CHANNEL_CLOSED;
    153153    event[1] = sizeof(event) - 2;
    154     bt_store_16(event, 2, channel->local_cid);
     154    little_endian_store_16(event, 2, channel->local_cid);
    155155    hci_dump_packet( HCI_EVENT_PACKET, 0, event, sizeof(event));
    156156    l2cap_dispatch(channel, HCI_EVENT_PACKET, event, sizeof(event));
     
    163163    event[0] = L2CAP_EVENT_INCOMING_CONNECTION;
    164164    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);
    170170    hci_dump_packet( HCI_EVENT_PACKET, 0, event, sizeof(event));
    171171    l2cap_dispatch(channel, HCI_EVENT_PACKET, event, sizeof(event));
     
    176176    event[0] = L2CAP_EVENT_CONNECTION_PARAMETER_UPDATE_RESPONSE;
    177177    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);
    180180    hci_dump_packet( HCI_EVENT_PACKET, 0, event, sizeof(event));
    181181    (*packet_handler)(NULL, HCI_EVENT_PACKET, 0, event, sizeof(event));
     
    188188    event[1] = sizeof(event) - 2;
    189189    event[2] = status;
    190     bt_store_16(event, 3, psm);
     190    little_endian_store_16(event, 3, psm);
    191191    hci_dump_packet( HCI_EVENT_PACKET, 0, event, sizeof(event));
    192192    (*packet_handler)(connection, HCI_EVENT_PACKET, 0, event, sizeof(event));
     
    201201    event[0] = L2CAP_EVENT_CREDITS;
    202202    event[1] = sizeof(event) - 2;
    203     bt_store_16(event, 2, channel->local_cid);
     203    little_endian_store_16(event, 2, channel->local_cid);
    204204    event[4] = credits;
    205205    hci_dump_packet( HCI_EVENT_PACKET, 0, event, sizeof(event));
     
    412412
    413413    // 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));
    415415    // 2 - ACL length
    416     bt_store_16(acl_buffer, 2,  len + 4);
     416    little_endian_store_16(acl_buffer, 2,  len + 4);
    417417    // 4 - L2CAP packet length
    418     bt_store_16(acl_buffer, 4,  len + 0);
     418    little_endian_store_16(acl_buffer, 4,  len + 0);
    419419    // 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);
    421421    // send
    422422    err = hci_send_acl_packet_buffer(len+8);
     
    449449
    450450    // 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));
    452452    // 2 - ACL length
    453     bt_store_16(acl_buffer, 2,  len + 4);
     453    little_endian_store_16(acl_buffer, 2,  len + 4);
    454454    // 4 - L2CAP packet length
    455     bt_store_16(acl_buffer, 4,  len + 0);
     455    little_endian_store_16(acl_buffer, 4,  len + 0);
    456456    // 6 - L2CAP channel DEST
    457     bt_store_16(acl_buffer, 6, cid);
     457    little_endian_store_16(acl_buffer, 6, cid);
    458458    // send
    459459    err = hci_send_acl_packet_buffer(len+8);
     
    665665                        config_options[0] = 1; // MTU
    666666                        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);
    668668                        l2cap_send_signaling_packet(channel->handle, CONFIGURE_RESPONSE, channel->remote_sig_id, channel->remote_cid, flags, 0, 4, &config_options);
    669669                        channelStateVarClearFlag(channel,L2CAP_CHANNEL_STATE_VAR_SEND_CONF_RSP_MTU);
     
    679679                    config_options[0] = 1; // MTU
    680680                    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);
    682682                    l2cap_send_signaling_packet(channel->handle, CONFIGURE_REQUEST, channel->local_sig_id, channel->remote_cid, 0, 4, &config_options);
    683683                    l2cap_start_rtx(channel);
     
    893893        // handle connection complete events
    894894        case HCI_EVENT_CONNECTION_COMPLETE:
    895             bt_flip_addr(address, &packet[5]);
     895            reverse_bd_addr(&packet[5], address);
    896896            if (packet[2] == 0){
    897                 handle = READ_BT_16(packet, 3);
     897                handle = little_endian_read_16(packet, 3);
    898898                l2cap_handle_connection_success_for_addr(address, handle);
    899899            } else {
     
    904904        // handle successful create connection cancel command
    905905        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) ) {
    907907                if (packet[5] == 0){
    908                     bt_flip_addr(address, &packet[6]);
     908                    reverse_bd_addr(&packet[6], address);
    909909                    // CONNECTION TERMINATED BY LOCAL HOST (0X16)
    910910                    l2cap_handle_connection_failed_for_addr(address, 0x16);
     
    921921        case HCI_EVENT_DISCONNECTION_COMPLETE:
    922922            // 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);
    924924            linked_list_iterator_init(&it, &l2cap_channels);
    925925            while (linked_list_iterator_has_next(&it)){
     
    940940        // HCI Connection Timeouts
    941941        case L2CAP_EVENT_TIMEOUT_CHECK:
    942             handle = READ_BT_16(packet, 2);
     942            handle = little_endian_read_16(packet, 2);
    943943            if (hci_authentication_active_for_handle(handle)) break;
    944944            hci_con_used = 0;
     
    971971
    972972        case HCI_EVENT_READ_REMOTE_SUPPORTED_FEATURES_COMPLETE:
    973             handle = READ_BT_16(packet, 3);
     973            handle = little_endian_read_16(packet, 3);
    974974            linked_list_iterator_init(&it, &l2cap_channels);
    975975            while (linked_list_iterator_has_next(&it)){
     
    982982
    983983        case GAP_SECURITY_LEVEL:
    984             handle = READ_BT_16(packet, 2);
     984            handle = little_endian_read_16(packet, 2);
    985985            log_info("l2cap - security level update");
    986986            linked_list_iterator_init(&it, &l2cap_channels);
     
    11631163    channel->remote_sig_id = command[L2CAP_SIGNALING_COMMAND_SIGID_OFFSET];
    11641164
    1165     flags = READ_BT_16(command, 6);
     1165    flags = little_endian_read_16(command, 6);
    11661166    if (flags & 1) {
    11671167        channelStateVarSetFlag(channel, L2CAP_CHANNEL_STATE_VAR_SEND_CONF_RSP_CONT);
     
    11691169
    11701170    // 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);
    11721172    pos     = 8;
    11731173    while (pos < end_pos){
     
    11801180        // MTU { type(8): 1, len(8):2, MTU(16) }
    11811181        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);
    11831183            // log_info("l2cap cid 0x%02x, remote mtu %u", channel->local_cid, channel->remote_mtu);
    11841184            channelStateVarSetFlag(channel, L2CAP_CHANNEL_STATE_VAR_SEND_CONF_RSP_MTU);
     
    11861186        // Flush timeout { type(8):2, len(8): 2, Flush Timeout(16)}
    11871187        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);
    11891189        }
    11901190        // check for unknown options
     
    12371237                case CONNECTION_RESPONSE:
    12381238                    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);
    12401240                    switch (result) {
    12411241                        case 0:
    12421242                            // 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);
    12441244                            channel->state = L2CAP_STATE_CONFIG;
    12451245                            channelStateVarSetFlag(channel, L2CAP_CHANNEL_STATE_VAR_SEND_CONF_REQ);
     
    12741274
    12751275        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);
    12771277            switch (code) {
    12781278                case CONFIGURE_REQUEST:
     
    13531353
    13541354        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);
    13571357            l2cap_handle_connection_request(handle, sig_id, psm, source_cid);
    13581358            return;
     
    13641364
    13651365        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);
    13671367            l2cap_register_signaling_response(handle, code, sig_id, infoType);
    13681368            return;
     
    13751375   
    13761376    // 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);
    13781378
    13791379    // Find channel for this sig_id and connection handle
     
    14151415
    14161416                // 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);
    14181418            }
    14191419            break;
     
    14351435            switch (packet[8]){
    14361436                case CONNECTION_PARAMETER_UPDATE_RESPONSE: {
    1437                     uint16_t result = READ_BT_16(packet, 12);
     1437                    uint16_t result = little_endian_read_16(packet, 12);
    14381438                    l2cap_emit_connection_parameter_update_response(handle, result);
    14391439                    break;
     
    14501450                        int update_parameter = 1;
    14511451                        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);
    14561456
    14571457                        if (le_conn_interval_min < existing_range.le_conn_interval_min) update_parameter = 0;
Note: See TracChangeset for help on using the changeset viewer.