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_rx/trunk/btstack/src/bnep.c

    r337 r374  
    8484    event[1] = sizeof(event) - 2;
    8585    event[2] = status;
    86     bt_store_16(event, 3, channel->l2cap_cid);
    87     bt_store_16(event, 5, channel->uuid_source);
    88     bt_store_16(event, 7, channel->uuid_dest);
    89     bt_store_16(event, 9, channel->max_frame_size);
     86    little_endian_store_16(event, 3, channel->l2cap_cid);
     87    little_endian_store_16(event, 5, channel->uuid_source);
     88    little_endian_store_16(event, 7, channel->uuid_dest);
     89    little_endian_store_16(event, 9, channel->max_frame_size);
    9090    BD_ADDR_COPY(&event[11], channel->remote_addr);
    9191    hci_dump_packet( HCI_EVENT_PACKET, 0, event, sizeof(event));
     
    101101    event[0] = BNEP_EVENT_CHANNEL_TIMEOUT;
    102102    event[1] = sizeof(event) - 2;
    103     bt_store_16(event, 2, channel->l2cap_cid);
    104     bt_store_16(event, 4, channel->uuid_source);
    105     bt_store_16(event, 6, channel->uuid_dest);
     103    little_endian_store_16(event, 2, channel->l2cap_cid);
     104    little_endian_store_16(event, 4, channel->uuid_source);
     105    little_endian_store_16(event, 6, channel->uuid_dest);
    106106    BD_ADDR_COPY(&event[8], channel->remote_addr);
    107107    event[14] = channel->state;
     
    118118    event[0] = BNEP_EVENT_CHANNEL_CLOSED;
    119119    event[1] = sizeof(event) - 2;
    120     bt_store_16(event, 2, channel->l2cap_cid);
    121     bt_store_16(event, 4, channel->uuid_source);
    122     bt_store_16(event, 6, channel->uuid_dest);
     120    little_endian_store_16(event, 2, channel->l2cap_cid);
     121    little_endian_store_16(event, 4, channel->uuid_source);
     122    little_endian_store_16(event, 6, channel->uuid_dest);
    123123    BD_ADDR_COPY(&event[8], channel->remote_addr);
    124124    hci_dump_packet( HCI_EVENT_PACKET, 0, event, sizeof(event));
     
    133133    event[0] = BNEP_EVENT_READY_TO_SEND;
    134134    event[1] = sizeof(event) - 2;
    135     bt_store_16(event, 2, channel->l2cap_cid);
     135    little_endian_store_16(event, 2, channel->l2cap_cid);
    136136    hci_dump_packet( HCI_EVENT_PACKET, 0, event, sizeof(event));
    137137        (*app_packet_handler)(channel->connection, HCI_EVENT_PACKET, 0, (uint8_t *) event, sizeof(event));
     
    464464    BD_ADDR_COPY(addr_source, &packet[pos]);
    465465    pos += sizeof(bd_addr_t);
    466     network_protocol_type = READ_NET_16(packet, pos);
     466    network_protocol_type = big_endian_read_16(packet, pos);
    467467    pos += sizeof(uint16_t);
    468468
     
    475475        }
    476476        /* The "real" network protocol type is 4 bytes ahead in a VLAN packet */
    477                 network_protocol_type = READ_NET_16(packet, pos + 2);
     477                network_protocol_type = big_endian_read_16(packet, pos + 2);
    478478        }
    479479
     
    808808    /* Check source and destination UUIDs for valid combinations */
    809809    if (response_code == BNEP_RESP_SETUP_SUCCESS) {
    810         channel->uuid_dest = READ_NET_16(packet, 2 + uuid_offset);
    811         channel->uuid_source = READ_NET_16(packet, 2 + uuid_offset + uuid_size);
    812 
    813         if ((channel->uuid_dest != BNEP_UUID_PANU) &&
    814             (channel->uuid_dest != BNEP_UUID_NAP) &&
    815             (channel->uuid_dest != BNEP_UUID_GN)) {
     810        channel->uuid_dest = big_endian_read_16(packet, 2 + uuid_offset);
     811        channel->uuid_source = big_endian_read_16(packet, 2 + uuid_offset + uuid_size);
     812
     813        if ((channel->uuid_dest != BLUETOOTH_SERVICE_CLASS_PANU) &&
     814            (channel->uuid_dest != BLUETOOTH_SERVICE_CLASS_NAP) &&
     815            (channel->uuid_dest != BLUETOOTH_SERVICE_CLASS_GN)) {
    816816            log_error("BNEP_CONNECTION_REQUEST: Invalid destination service UUID: %04x", channel->uuid_dest);
    817817            channel->uuid_dest = 0;
    818818        }
    819         if ((channel->uuid_source != BNEP_UUID_PANU) &&
    820             (channel->uuid_source != BNEP_UUID_NAP) &&
    821             (channel->uuid_source != BNEP_UUID_GN)) {
     819        if ((channel->uuid_source != BLUETOOTH_SERVICE_CLASS_PANU) &&
     820            (channel->uuid_source != BLUETOOTH_SERVICE_CLASS_NAP) &&
     821            (channel->uuid_source != BLUETOOTH_SERVICE_CLASS_GN)) {
    822822            log_error("BNEP_CONNECTION_REQUEST: Invalid source service UUID: %04x", channel->uuid_source);
    823823            channel->uuid_source = 0;
     
    829829            response_code = BNEP_RESP_SETUP_INVALID_DEST_UUID;
    830830        } else
    831         if ((channel->uuid_source != BNEP_UUID_PANU) && (channel->uuid_dest != BNEP_UUID_PANU)) {
     831        if ((channel->uuid_source != BLUETOOTH_SERVICE_CLASS_PANU) && (channel->uuid_dest != BLUETOOTH_SERVICE_CLASS_PANU)) {
    832832            response_code = BNEP_RESP_SETUP_INVALID_SOURCE_UUID;
    833833        }
     
    857857    }
    858858
    859     response_code = READ_NET_16(packet, 1);
     859    response_code = big_endian_read_16(packet, 1);
    860860
    861861    if (response_code == BNEP_RESP_SETUP_SUCCESS) {
     
    882882    }
    883883
    884     list_length = READ_NET_16(packet, 1);
     884    list_length = big_endian_read_16(packet, 1);
    885885    /* Sanity check packet size again with known package size */
    886886    if (size < 3 + list_length) {
     
    903903        /* There is still enough space, copy the filters to our filter list */
    904904        for (i = 0; i < list_length / (2 * 2); i ++) {
    905             channel->net_filter[channel->net_filter_count].range_start = READ_NET_16(packet, 1 + 2 + i * 4);
    906             channel->net_filter[channel->net_filter_count].range_end = READ_NET_16(packet, 1 + 2 + i * 4 + 2);
     905            channel->net_filter[channel->net_filter_count].range_start = big_endian_read_16(packet, 1 + 2 + i * 4);
     906            channel->net_filter[channel->net_filter_count].range_end = big_endian_read_16(packet, 1 + 2 + i * 4 + 2);
    907907            if (channel->net_filter[channel->net_filter_count].range_start > channel->net_filter[channel->net_filter_count].range_end) {
    908908                /* Invalid filter range, ignore this filter rule */
     
    945945    }
    946946
    947     response_code = READ_NET_16(packet, 1);
     947    response_code = big_endian_read_16(packet, 1);
    948948
    949949    if (response_code == BNEP_RESP_FILTER_SUCCESS) {
     
    966966    }
    967967
    968     list_length = READ_NET_16(packet, 1);
     968    list_length = big_endian_read_16(packet, 1);
    969969    /* Sanity check packet size again with known package size */
    970970    if (size < 3 + list_length) {
     
    10321032    }
    10331033
    1034     response_code = READ_NET_16(packet, 1);
     1034    response_code = big_endian_read_16(packet, 1);
    10351035
    10361036    if (response_code == BNEP_RESP_FILTER_SUCCESS) {
     
    11691169        case L2CAP_EVENT_INCOMING_CONNECTION:
    11701170            /* L2CAP event data: event(8), len(8), address(48), handle (16),  psm (16), source cid(16) dest cid(16) */
    1171             bt_flip_addr(event_addr, &packet[2]);
    1172             con_handle = READ_BT_16(packet,  8);
    1173             psm        = READ_BT_16(packet, 10);
    1174             l2cap_cid  = READ_BT_16(packet, 12);
     1171            reverse_bd_addr(&packet[2], event_addr);
     1172            con_handle = little_endian_read_16(packet,  8);
     1173            psm        = little_endian_read_16(packet, 10);
     1174            l2cap_cid  = little_endian_read_16(packet, 12);
    11751175
    11761176            if (psm != PSM_BNEP) break;
     
    12111211        case L2CAP_EVENT_CHANNEL_OPENED:
    12121212            /* Check if the l2cap channel has been opened for PSM_BNEP */
    1213             if (READ_BT_16(packet, 11) != PSM_BNEP) {
     1213            if (little_endian_read_16(packet, 11) != PSM_BNEP) {
    12141214                break;
    12151215            }
     
    12191219
    12201220            /* Get the bnep channel fpr remote address */
    1221             con_handle = READ_BT_16(packet, 9);
    1222             l2cap_cid  = READ_BT_16(packet, 13);
    1223             bt_flip_addr(event_addr, &packet[3]);
     1221            con_handle = little_endian_read_16(packet, 9);
     1222            l2cap_cid  = little_endian_read_16(packet, 13);
     1223            reverse_bd_addr(&packet[3], event_addr);
    12241224            channel = bnep_channel_for_addr(&event_addr);
    12251225            if (!channel) {
     
    12521252                    channel->state = BNEP_CHANNEL_STATE_WAIT_FOR_CONNECTION_RESPONSE;
    12531253                    bnep_channel_state_add(channel, BNEP_CHANNEL_STATE_VAR_SND_CONNECTION_REQUEST);
    1254                     channel->max_frame_size = bnep_max_frame_size_for_l2cap_mtu(READ_BT_16(packet, 17));
     1254                    channel->max_frame_size = bnep_max_frame_size_for_l2cap_mtu(little_endian_read_16(packet, 17));
    12551255                    bnep_run();
    12561256                    break;
    12571257                case BNEP_CHANNEL_STATE_WAIT_FOR_CONNECTION_REQUEST:
    12581258                    /* New information: channel mtu */
    1259                     channel->max_frame_size = bnep_max_frame_size_for_l2cap_mtu(READ_BT_16(packet, 17));
     1259                    channel->max_frame_size = bnep_max_frame_size_for_l2cap_mtu(little_endian_read_16(packet, 17));
    12601260                    break;
    12611261                default:
     
    12721272        case L2CAP_EVENT_CHANNEL_CLOSED:
    12731273            // data: event (8), len(8), channel (16)
    1274             l2cap_cid   = READ_BT_16(packet, 2);
     1274            l2cap_cid   = little_endian_read_16(packet, 2);
    12751275            channel = bnep_channel_for_l2cap_cid(l2cap_cid);
    12761276            log_info("L2CAP_EVENT_CHANNEL_CLOSED cid 0x%0x, channel %p", l2cap_cid, channel);
     
    13311331            BD_ADDR_COPY(addr_source, &packet[pos]);
    13321332            pos += sizeof(bd_addr_t);
    1333             network_protocol_type = READ_NET_16(packet, pos);
     1333            network_protocol_type = big_endian_read_16(packet, pos);
    13341334            pos += 2;
    13351335            break;
     
    13371337            BD_ADDR_COPY(addr_dest, channel->local_addr);
    13381338            BD_ADDR_COPY(addr_source, channel->remote_addr);
    1339             network_protocol_type = READ_NET_16(packet, pos);
     1339            network_protocol_type = big_endian_read_16(packet, pos);
    13401340            pos += 2;
    13411341            break;
     
    13441344            BD_ADDR_COPY(addr_source, &packet[pos]);
    13451345            pos += sizeof(bd_addr_t);
    1346             network_protocol_type = READ_NET_16(packet, pos);
     1346            network_protocol_type = big_endian_read_16(packet, pos);
    13471347            pos += 2;
    13481348            break;
     
    13511351            pos += sizeof(bd_addr_t);
    13521352            BD_ADDR_COPY(addr_source, channel->remote_addr);
    1353             network_protocol_type = READ_NET_16(packet, pos);
     1353            network_protocol_type = big_endian_read_16(packet, pos);
    13541354            pos += 2;
    13551355            break;
     
    15631563    }
    15641564
    1565     channel->uuid_source = BNEP_UUID_PANU;
     1565    channel->uuid_source = BLUETOOTH_SERVICE_CLASS_PANU;
    15661566    channel->uuid_dest   = uuid_dest;
    15671567
     
    15971597
    15981598    /* Only alow one the three service types: PANU, NAP, GN */
    1599     if ((service_uuid != BNEP_UUID_PANU) &&
    1600         (service_uuid != BNEP_UUID_NAP) &&
    1601         (service_uuid != BNEP_UUID_GN)) {
     1599    if ((service_uuid != BLUETOOTH_SERVICE_CLASS_PANU) &&
     1600        (service_uuid != BLUETOOTH_SERVICE_CLASS_NAP) &&
     1601        (service_uuid != BLUETOOTH_SERVICE_CLASS_GN)) {
    16021602        log_info("BNEP_REGISTER_SERVICE: Invalid service UUID: %04x", service_uuid);
    16031603        return BNEP_CHANNEL_NOT_CONNECTED;
Note: See TracChangeset for help on using the changeset viewer.