[352] | 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
|
---|
| 9 | * notice, this list of conditions and the following disclaimer.
|
---|
| 10 | * 2. Redistributions in binary form must reproduce the above copyright
|
---|
| 11 | * notice, this list of conditions and the following disclaimer in the
|
---|
| 12 | * documentation and/or other materials provided with the distribution.
|
---|
| 13 | * 3. Neither the name of the copyright holders nor the names of
|
---|
| 14 | * contributors may be used to endorse or promote products derived
|
---|
| 15 | * from this software without specific prior written permission.
|
---|
| 16 | * 4. Any redistribution, use, or modification is done solely for
|
---|
| 17 | * personal benefit and not for any commercial purpose or for
|
---|
| 18 | * monetary gain.
|
---|
| 19 | *
|
---|
| 20 | * THIS SOFTWARE IS PROVIDED BY BLUEKITCHEN GMBH AND CONTRIBUTORS
|
---|
| 21 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
---|
| 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
---|
| 23 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL MATTHIAS
|
---|
| 24 | * RINGWALD OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
| 25 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
---|
| 26 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
---|
| 27 | * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
---|
| 28 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
---|
| 29 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
|
---|
| 30 | * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
---|
| 31 | * SUCH DAMAGE.
|
---|
| 32 | *
|
---|
| 33 | * Please inquire about commercial licensing options at
|
---|
| 34 | * contact@bluekitchen-gmbh.com
|
---|
| 35 | *
|
---|
| 36 | */
|
---|
| 37 |
|
---|
| 38 | #include "btstack-config.h"
|
---|
| 39 |
|
---|
| 40 | #include <stdint.h>
|
---|
| 41 |
|
---|
| 42 | #include <btstack/hci_cmds.h>
|
---|
| 43 | #include <btstack/run_loop.h>
|
---|
| 44 | #include <btstack/sdp_util.h>
|
---|
| 45 |
|
---|
| 46 | #include <kernel.h>
|
---|
| 47 | #include "kernel_cfg.h"
|
---|
| 48 | #include "target_syssvc.h"
|
---|
| 49 |
|
---|
| 50 | #include "debug.h"
|
---|
| 51 | #include "hci.h"
|
---|
| 52 | #include "btstack_memory.h"
|
---|
| 53 | #include "hci_dump.h"
|
---|
| 54 | #include "l2cap.h"
|
---|
| 55 | #include "sdp_parser.h"
|
---|
| 56 | #include "sdp_client.h"
|
---|
| 57 | #include "sdp_query_util.h"
|
---|
| 58 | #include "sdp.h"
|
---|
| 59 | #include "pan.h"
|
---|
| 60 | #include "panu_main.h"
|
---|
| 61 |
|
---|
| 62 | extern uint16_t rfcomm_channel_id;
|
---|
| 63 |
|
---|
| 64 | static int record_id = -1;
|
---|
| 65 | static uint16_t bnep_l2cap_psm = 0;
|
---|
| 66 | static uint32_t bnep_remote_uuid = 0;
|
---|
| 67 | static uint16_t bnep_version = 0;
|
---|
| 68 | static uint16_t bnep_cid = 0;
|
---|
| 69 | static bool_t bnep_do_connect = false;
|
---|
| 70 |
|
---|
| 71 | static uint16_t sdp_bnep_l2cap_psm = 0;
|
---|
| 72 | static uint16_t sdp_bnep_version = 0;
|
---|
| 73 | static uint32_t sdp_bnep_remote_uuid = 0;
|
---|
| 74 |
|
---|
| 75 | extern uint8_t attribute_value[];
|
---|
| 76 | extern const unsigned int attribute_value_buffer_size;
|
---|
| 77 |
|
---|
| 78 | static bd_addr_t remote_addr;
|
---|
| 79 |
|
---|
| 80 | extern uint8_t spp_service_buffer[120];
|
---|
| 81 | extern uint8_t bnep_service_buffer[256];
|
---|
| 82 |
|
---|
| 83 | extern char bt_localname[sizeof(TARGET_NAME"0000")];
|
---|
| 84 |
|
---|
| 85 | /*************** NAP server routines *********************/
|
---|
| 86 |
|
---|
| 87 | char * get_string_from_data_element(uint8_t * element);
|
---|
| 88 |
|
---|
| 89 | /* @section SDP parser callback
|
---|
| 90 | *
|
---|
| 91 | * @text The SDP parsers retrieves the BNEP PAN UUID as explained in
|
---|
| 92 | * Section [on SDP BNEP Query example](#sec:sdpbnepqueryExample}.
|
---|
| 93 | */
|
---|
| 94 | static void handle_sdp_client_record_complete(void)
|
---|
| 95 | {
|
---|
| 96 | log_info("SDP BNEP Record complete");
|
---|
| 97 |
|
---|
| 98 | // accept first entry or if we foudn a PANU and only have a NAP yet
|
---|
| 99 | if ((bnep_remote_uuid == 0) || (sdp_bnep_remote_uuid == BNEP_UUID_PANU && bnep_remote_uuid == BNEP_UUID_NAP)) {
|
---|
| 100 | bnep_l2cap_psm = sdp_bnep_l2cap_psm;
|
---|
| 101 | bnep_remote_uuid = sdp_bnep_remote_uuid;
|
---|
| 102 | bnep_version = sdp_bnep_version;
|
---|
| 103 | }
|
---|
| 104 | }
|
---|
| 105 |
|
---|
| 106 | /* SDP parser callback */
|
---|
| 107 | static void handle_sdp_client_query_result(sdp_query_event_t *event)
|
---|
| 108 | {
|
---|
| 109 | sdp_query_attribute_value_event_t *value_event;
|
---|
| 110 | sdp_query_complete_event_t *complete_event;
|
---|
| 111 | des_iterator_t des_list_it;
|
---|
| 112 | des_iterator_t prot_it;
|
---|
| 113 | char *str;
|
---|
| 114 |
|
---|
| 115 | switch (event->type) {
|
---|
| 116 | case SDP_QUERY_ATTRIBUTE_VALUE:
|
---|
| 117 | value_event = (sdp_query_attribute_value_event_t*)event;
|
---|
| 118 |
|
---|
| 119 | // Handle new SDP record
|
---|
| 120 | if (value_event->record_id != record_id) {
|
---|
| 121 | handle_sdp_client_record_complete();
|
---|
| 122 | // next record started
|
---|
| 123 | record_id = value_event->record_id;
|
---|
| 124 | log_info("SDP Record: Nr: %d", record_id);
|
---|
| 125 | }
|
---|
| 126 |
|
---|
| 127 | if (value_event->attribute_length <= attribute_value_buffer_size) {
|
---|
| 128 | attribute_value[value_event->data_offset] = value_event->data;
|
---|
| 129 |
|
---|
| 130 | if ((uint16_t)(value_event->data_offset + 1) == value_event->attribute_length) {
|
---|
| 131 | //printf("SDP Attribute Data:");
|
---|
| 132 | //printf_hexdump(attribute_value, value_event->attribute_length);
|
---|
| 133 |
|
---|
| 134 | switch (value_event->attribute_id) {
|
---|
| 135 | case SDP_ServiceClassIDList:
|
---|
| 136 | if (de_get_element_type(attribute_value) != DE_DES) break;
|
---|
| 137 | for (des_iterator_init(&des_list_it, attribute_value); des_iterator_has_more(&des_list_it); des_iterator_next(&des_list_it)) {
|
---|
| 138 | uint8_t * element = des_iterator_get_element(&des_list_it);
|
---|
| 139 | if (de_get_element_type(element) != DE_UUID) continue;
|
---|
| 140 | uint32_t uuid = de_get_uuid32(element);
|
---|
| 141 | switch (uuid) {
|
---|
| 142 | case BNEP_UUID_PANU:
|
---|
| 143 | case BNEP_UUID_NAP:
|
---|
| 144 | case BNEP_UUID_GN:
|
---|
| 145 | log_info("SDP Attribute 0x%04x: BNEP PAN protocol UUID: %04x", value_event->attribute_id, uuid);
|
---|
| 146 | sdp_bnep_remote_uuid = uuid;
|
---|
| 147 | break;
|
---|
| 148 | default:
|
---|
| 149 | log_info("SDP Attribute 0x%04x: UUID: %04x", value_event->attribute_id, uuid);
|
---|
| 150 | break;
|
---|
| 151 | }
|
---|
| 152 | }
|
---|
| 153 | break;
|
---|
| 154 | // 0x0100 "Service Name"
|
---|
| 155 | case 0x0100:
|
---|
| 156 | // 0x0101 "Service Description"
|
---|
| 157 | case 0x0101:
|
---|
| 158 | str = get_string_from_data_element(attribute_value);
|
---|
| 159 | log_info("SDP Attribute: 0x%04x: %s", value_event->attribute_id, str);
|
---|
| 160 | free(str);
|
---|
| 161 | break;
|
---|
| 162 | case SDP_ProtocolDescriptorList: {
|
---|
| 163 | log_info("SDP Attribute: 0x%04x", value_event->attribute_id);
|
---|
| 164 |
|
---|
| 165 | for (des_iterator_init(&des_list_it, attribute_value); des_iterator_has_more(&des_list_it); des_iterator_next(&des_list_it)) {
|
---|
| 166 | uint8_t *des_element;
|
---|
| 167 | uint8_t *element;
|
---|
| 168 | uint32_t uuid;
|
---|
| 169 |
|
---|
| 170 | if (des_iterator_get_type(&des_list_it) != DE_DES) continue;
|
---|
| 171 |
|
---|
| 172 | des_element = des_iterator_get_element(&des_list_it);
|
---|
| 173 | des_iterator_init(&prot_it, des_element);
|
---|
| 174 | element = des_iterator_get_element(&prot_it);
|
---|
| 175 |
|
---|
| 176 | if (de_get_element_type(element) != DE_UUID) continue;
|
---|
| 177 |
|
---|
| 178 | uuid = de_get_uuid32(element);
|
---|
| 179 | switch (uuid) {
|
---|
| 180 | case SDP_L2CAPProtocol:
|
---|
| 181 | if (!des_iterator_has_more(&prot_it)) continue;
|
---|
| 182 | des_iterator_next(&prot_it);
|
---|
| 183 | de_element_get_uint16(des_iterator_get_element(&prot_it), &sdp_bnep_l2cap_psm);
|
---|
| 184 | break;
|
---|
| 185 | case SDP_BNEPProtocol:
|
---|
| 186 | if (!des_iterator_has_more(&prot_it)) continue;
|
---|
| 187 | des_iterator_next(&prot_it);
|
---|
| 188 | de_element_get_uint16(des_iterator_get_element(&prot_it), &sdp_bnep_version);
|
---|
| 189 | break;
|
---|
| 190 | default:
|
---|
| 191 | log_info("uuid 0x%04x", uuid);
|
---|
| 192 | break;
|
---|
| 193 | }
|
---|
| 194 | }
|
---|
| 195 | log_info("Summary: uuid 0x%04x, l2cap_psm 0x%04x, bnep_version 0x%04x", sdp_bnep_remote_uuid, sdp_bnep_l2cap_psm, sdp_bnep_version);
|
---|
| 196 | break;
|
---|
| 197 | }
|
---|
| 198 | default:
|
---|
| 199 | break;
|
---|
| 200 | }
|
---|
| 201 | }
|
---|
| 202 | }
|
---|
| 203 | else {
|
---|
| 204 | log_error("SDP attribute value buffer size exceeded: available %d, required %d", attribute_value_buffer_size, value_event->attribute_length);
|
---|
| 205 | }
|
---|
| 206 | break;
|
---|
| 207 |
|
---|
| 208 | case SDP_QUERY_COMPLETE:
|
---|
| 209 | handle_sdp_client_record_complete();
|
---|
| 210 | complete_event = (sdp_query_complete_event_t*)event;
|
---|
| 211 | log_error("General query done with status %d, bnep psm %04x.", complete_event->status, bnep_l2cap_psm);
|
---|
| 212 | if (bnep_l2cap_psm) {
|
---|
| 213 | bnep_do_connect = complete_event->status == 0;
|
---|
| 214 | }
|
---|
| 215 | else {
|
---|
| 216 | log_error("No BNEP service found");
|
---|
| 217 | }
|
---|
| 218 | break;
|
---|
| 219 | }
|
---|
| 220 | }
|
---|
| 221 |
|
---|
| 222 | static void packet_handler(void * connection, uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size)
|
---|
| 223 | {
|
---|
| 224 | uint8_t event;
|
---|
| 225 | bd_addr_t event_addr;
|
---|
| 226 | uint8_t rfcomm_channel_nr;
|
---|
| 227 | uint16_t uuid_source;
|
---|
| 228 | uint16_t uuid_dest;
|
---|
| 229 | uint16_t mtu;
|
---|
| 230 |
|
---|
| 231 | switch (packet_type) {
|
---|
| 232 | case HCI_EVENT_PACKET:
|
---|
| 233 | event = packet[0];
|
---|
| 234 | switch (event) {
|
---|
| 235 | case BTSTACK_EVENT_STATE:
|
---|
| 236 | /* BT Stack activated, get started */
|
---|
| 237 | if (packet[2] == HCI_STATE_WORKING) {
|
---|
| 238 | hci_send_cmd(&hci_write_local_name, bt_localname);
|
---|
| 239 | }
|
---|
| 240 | break;
|
---|
| 241 |
|
---|
| 242 | case BTSTACK_EVENT_NR_CONNECTIONS_CHANGED:
|
---|
| 243 | if ((packet[2] == 0) && bnep_do_connect) {
|
---|
| 244 | bnep_do_connect = false;
|
---|
| 245 | /* Create BNEP connection */
|
---|
| 246 | bnep_connect(NULL, &remote_addr, bnep_l2cap_psm, bnep_remote_uuid);
|
---|
| 247 | }
|
---|
| 248 | break;
|
---|
| 249 |
|
---|
| 250 | case HCI_EVENT_COMMAND_COMPLETE:
|
---|
| 251 | if (COMMAND_COMPLETE_EVENT(packet, hci_read_bd_addr)) {
|
---|
| 252 | bt_flip_addr(event_addr, &packet[6]);
|
---|
| 253 | log_info("BD-ADDR: %s", bd_addr_to_str(event_addr));
|
---|
| 254 |
|
---|
| 255 | snprintf(bt_localname, sizeof(bt_localname), TARGET_NAME"%04x", ((event_addr[4] << 8) | event_addr[5]));
|
---|
| 256 | gap_set_local_name(bt_localname);
|
---|
| 257 | break;
|
---|
| 258 | }
|
---|
| 259 | if (COMMAND_COMPLETE_EVENT(packet, hci_write_local_name)) {
|
---|
| 260 | hci_discoverable_control(1);
|
---|
| 261 | break;
|
---|
| 262 | }
|
---|
| 263 | break;
|
---|
| 264 |
|
---|
| 265 | case HCI_EVENT_LINK_KEY_REQUEST:
|
---|
| 266 | // deny link key request
|
---|
| 267 | log_info("Link key request");
|
---|
| 268 | bt_flip_addr(event_addr, &packet[2]);
|
---|
| 269 | hci_send_cmd(&hci_link_key_request_negative_reply, &event_addr);
|
---|
| 270 | break;
|
---|
| 271 |
|
---|
| 272 | case HCI_EVENT_PIN_CODE_REQUEST:
|
---|
| 273 | // inform about pin code request
|
---|
| 274 | log_info("Pin code request - using '0000'");
|
---|
| 275 | bt_flip_addr(event_addr, &packet[2]);
|
---|
| 276 | hci_send_cmd(&hci_pin_code_request_reply, &event_addr, 4, "0000");
|
---|
| 277 | break;
|
---|
| 278 |
|
---|
| 279 | case HCI_EVENT_USER_CONFIRMATION_REQUEST:
|
---|
| 280 | // inform about user confirmation request
|
---|
| 281 | log_info("HCI User Confirmation Request with numeric value '%06u'", READ_BT_32(packet, 8));
|
---|
| 282 | log_info("HCI User Confirmation Auto accept");
|
---|
| 283 | break;
|
---|
| 284 |
|
---|
| 285 | case RFCOMM_EVENT_INCOMING_CONNECTION:
|
---|
| 286 | // data: event (8), len(8), address(48), channel (8), rfcomm_cid (16)
|
---|
| 287 | bt_flip_addr(event_addr, &packet[2]);
|
---|
| 288 | rfcomm_channel_nr = packet[8];
|
---|
| 289 | rfcomm_channel_id = READ_BT_16(packet, 9);
|
---|
| 290 | log_info("RFCOMM channel %u requested for %s", rfcomm_channel_nr, bd_addr_to_str(event_addr));
|
---|
| 291 | rfcomm_accept_connection_internal(rfcomm_channel_id);
|
---|
| 292 | break;
|
---|
| 293 |
|
---|
| 294 | case RFCOMM_EVENT_OPEN_CHANNEL_COMPLETE:
|
---|
| 295 | // data: event(8), len(8), status (8), address (48), server channel(8), rfcomm_cid(16), max frame size(16)
|
---|
| 296 | if (packet[2]) {
|
---|
| 297 | log_info("RFCOMM channel open failed, status %u", packet[2]);
|
---|
| 298 | }
|
---|
| 299 | else {
|
---|
| 300 | rfcomm_channel_id = READ_BT_16(packet, 12);
|
---|
| 301 | mtu = READ_BT_16(packet, 14);
|
---|
| 302 | log_info("RFCOMM channel open succeeded. New RFCOMM Channel ID %u, max frame size %u", rfcomm_channel_id, mtu);
|
---|
| 303 | }
|
---|
| 304 | break;
|
---|
| 305 |
|
---|
| 306 | case RFCOMM_EVENT_CHANNEL_CLOSED:
|
---|
| 307 | log_info("RFCOMM channel closed");
|
---|
| 308 | rfcomm_channel_id = 0;
|
---|
| 309 | break;
|
---|
| 310 |
|
---|
| 311 | case BNEP_EVENT_OPEN_CHANNEL_COMPLETE:
|
---|
| 312 | if (packet[2]) {
|
---|
| 313 | log_info("BNEP channel open failed, status %02x", packet[2]);
|
---|
| 314 | }
|
---|
| 315 | else {
|
---|
| 316 | // data: event(8), len(8), status (8), bnep source uuid (16), bnep destination uuid (16), remote_address (48)
|
---|
| 317 | bnep_cid = READ_BT_16(packet, 3);
|
---|
| 318 | uuid_source = READ_BT_16(packet, 5);
|
---|
| 319 | uuid_dest = READ_BT_16(packet, 7);
|
---|
| 320 | mtu = READ_BT_16(packet, 9);
|
---|
| 321 | //bt_flip_addr(remote_addr, &packet[11]);
|
---|
| 322 | memcpy(&remote_addr, &packet[11], sizeof(bd_addr_t));
|
---|
| 323 | log_info("BNEP connection open succeeded to %s source UUID 0x%04x dest UUID: 0x%04x, max frame size %u", bd_addr_to_str(event_addr), uuid_source, uuid_dest, mtu);
|
---|
| 324 | /* Setup network interface */
|
---|
| 325 | btstack_network_up(bnep_cid, (uint8_t *)hci_local_bd_addr(), remote_addr);
|
---|
| 326 | log_info("Network Interface %s activated", btstack_network_get_name(bnep_cid));
|
---|
| 327 | }
|
---|
| 328 | break;
|
---|
| 329 |
|
---|
| 330 | case BNEP_EVENT_CHANNEL_TIMEOUT:
|
---|
| 331 | log_info("BNEP channel timeout! Channel will be closed");
|
---|
| 332 | break;
|
---|
| 333 |
|
---|
| 334 | case BNEP_EVENT_CHANNEL_CLOSED:
|
---|
| 335 | bnep_cid = READ_BT_16(packet, 2);
|
---|
| 336 | bt_channel_closed(bnep_cid);
|
---|
| 337 | break;
|
---|
| 338 |
|
---|
| 339 | case BNEP_EVENT_READY_TO_SEND:
|
---|
| 340 | bnep_cid = READ_BT_16(packet, 2);
|
---|
| 341 | bt_send_packet(bnep_cid);
|
---|
| 342 | break;
|
---|
| 343 |
|
---|
| 344 | default:
|
---|
| 345 | break;
|
---|
| 346 | }
|
---|
| 347 | break;
|
---|
| 348 |
|
---|
| 349 | case RFCOMM_DATA_PACKET:
|
---|
| 350 | // loopback
|
---|
| 351 | if (rfcomm_channel_id) {
|
---|
| 352 | int err = rfcomm_send_internal(rfcomm_channel_id, packet, size);
|
---|
| 353 | if (err) {
|
---|
| 354 | log_error("rfcomm_send_internal -> error %d", err);
|
---|
| 355 | }
|
---|
| 356 | }
|
---|
| 357 | break;
|
---|
| 358 |
|
---|
| 359 | case BNEP_DATA_PACKET:
|
---|
| 360 | bt_recv_packet(channel, packet, size);
|
---|
| 361 | break;
|
---|
| 362 |
|
---|
| 363 | default:
|
---|
| 364 | break;
|
---|
| 365 | }
|
---|
| 366 | }
|
---|
| 367 |
|
---|
| 368 | void nap_init(void)
|
---|
| 369 | {
|
---|
| 370 | const hci_transport_t *transport;
|
---|
| 371 | bt_control_t * control;
|
---|
| 372 | hci_uart_config_t * config;
|
---|
| 373 | remote_device_db_t * remote_db;
|
---|
| 374 | service_record_item_t *spp_service_record_item;
|
---|
| 375 | service_record_item_t *bnep_service_record_item;
|
---|
| 376 |
|
---|
| 377 | //hci_dump_open("", HCI_DUMP_PACKETLOGGER);
|
---|
| 378 |
|
---|
| 379 | log_info("bt初期化...");
|
---|
| 380 |
|
---|
| 381 | // start with BTstack init - especially configure HCI Transport
|
---|
| 382 | btstack_memory_init();
|
---|
| 383 | run_loop_init(RUN_LOOP_EMBEDDED);
|
---|
| 384 |
|
---|
| 385 | /* Initialize HCI */
|
---|
| 386 | log_info("HCI初期化...");
|
---|
| 387 | transport = hci_transport_usb_instance();
|
---|
| 388 | control = NULL;
|
---|
| 389 | config = NULL;
|
---|
| 390 | remote_db = (remote_device_db_t *)&remote_device_db_memory;
|
---|
| 391 | hci_init(transport, config, control, remote_db);
|
---|
| 392 | hci_set_class_of_device(0x820300/*0x820810*/);
|
---|
| 393 |
|
---|
| 394 | /* Initialize L2CAP */
|
---|
| 395 | log_info("L2CAP初期化...");
|
---|
| 396 | l2cap_init();
|
---|
| 397 | l2cap_register_packet_handler(packet_handler);
|
---|
| 398 |
|
---|
| 399 | /* Initialise SDP, create record for SPP and register with SDP */
|
---|
| 400 | log_info("SDP初期化...");
|
---|
| 401 | sdp_init();
|
---|
| 402 |
|
---|
| 403 | /* Initialize RFCOMM */
|
---|
| 404 | log_info("RFCOMM初期化...");
|
---|
| 405 | rfcomm_init();
|
---|
| 406 | rfcomm_register_packet_handler(packet_handler);
|
---|
| 407 | rfcomm_register_service_internal(NULL, RFCOMM_SERVER_CHANNEL, 0xffff); // reserved channel, mtu=100
|
---|
| 408 |
|
---|
| 409 | /* Initialise BNEP */
|
---|
| 410 | log_info("BNEP初期化...");
|
---|
| 411 | bnep_init();
|
---|
| 412 | bnep_register_packet_handler(packet_handler);
|
---|
| 413 | bnep_register_service(NULL, BNEP_UUID_NAP, BNEP_MTU_MIN); /* Minimum L2CAP MTU for bnep is 1691 bytes */
|
---|
| 414 |
|
---|
| 415 | memset(spp_service_buffer, 0, sizeof(spp_service_buffer));
|
---|
| 416 | memset(bnep_service_buffer, 0, sizeof(bnep_service_buffer));
|
---|
| 417 |
|
---|
| 418 | // サービス定義
|
---|
| 419 | spp_service_record_item = (service_record_item_t *)spp_service_buffer;
|
---|
| 420 | bnep_service_record_item = (service_record_item_t *)bnep_service_buffer;
|
---|
| 421 |
|
---|
| 422 | log_info("SPPサービス登録...");
|
---|
| 423 | sdp_create_spp_service((uint8_t*)&spp_service_record_item->service_record, 1, "RX SPP");
|
---|
| 424 | de_dump_data_element((uint8_t*)spp_service_record_item->service_record);
|
---|
| 425 | log_info("SSP SDP service buffer size: %u", (uint16_t)(sizeof(service_record_item_t) + de_get_len((uint8_t*)spp_service_record_item->service_record)));
|
---|
| 426 | sdp_register_service_internal(NULL, spp_service_record_item);
|
---|
| 427 |
|
---|
| 428 | log_info("BNEPサービス登録...");
|
---|
| 429 | pan_create_nap_service((uint8_t*)&bnep_service_record_item->service_record, "RX NAP", "RX NAP", BNEP_SECURITY_NONE,
|
---|
| 430 | PAN_NET_ACCESS_TYPE_100MB_ETHERNET, 0x0001312D0/*10Mb/sec*/, NULL, NULL);
|
---|
| 431 | de_dump_data_element((uint8_t*)bnep_service_record_item->service_record);
|
---|
| 432 | log_info("NAP SDP service buffer size: %u", (uint16_t)(sizeof(service_record_item_t) + de_get_len((uint8_t*)bnep_service_record_item->service_record)));
|
---|
| 433 | sdp_register_service_internal(NULL, bnep_service_record_item);
|
---|
| 434 |
|
---|
| 435 | // Secure Simple Pairing configuration -> just works
|
---|
| 436 | hci_ssp_set_enable(1);
|
---|
| 437 | hci_ssp_set_io_capability(SSP_IO_CAPABILITY_NO_INPUT_NO_OUTPUT);
|
---|
| 438 | hci_ssp_set_auto_accept(1);
|
---|
| 439 |
|
---|
| 440 | /* Turn on the device */
|
---|
| 441 | log_info("HCI電源ON...");
|
---|
| 442 | hci_power_control(HCI_POWER_ON);
|
---|
| 443 |
|
---|
| 444 | /* Initialise SDP */
|
---|
| 445 | sdp_parser_init();
|
---|
| 446 | sdp_parser_register_callback(handle_sdp_client_query_result);
|
---|
| 447 | }
|
---|