1cee62800SMatthias Ringwald /* 2cee62800SMatthias Ringwald * Copyright (C) 2014 BlueKitchen GmbH 3cee62800SMatthias Ringwald * 4cee62800SMatthias Ringwald * Redistribution and use in source and binary forms, with or without 5cee62800SMatthias Ringwald * modification, are permitted provided that the following conditions 6cee62800SMatthias Ringwald * are met: 7cee62800SMatthias Ringwald * 8cee62800SMatthias Ringwald * 1. Redistributions of source code must retain the above copyright 9cee62800SMatthias Ringwald * notice, this list of conditions and the following disclaimer. 10cee62800SMatthias Ringwald * 2. Redistributions in binary form must reproduce the above copyright 11cee62800SMatthias Ringwald * notice, this list of conditions and the following disclaimer in the 12cee62800SMatthias Ringwald * documentation and/or other materials provided with the distribution. 13cee62800SMatthias Ringwald * 3. Neither the name of the copyright holders nor the names of 14cee62800SMatthias Ringwald * contributors may be used to endorse or promote products derived 15cee62800SMatthias Ringwald * from this software without specific prior written permission. 16cee62800SMatthias Ringwald * 4. Any redistribution, use, or modification is done solely for 17cee62800SMatthias Ringwald * personal benefit and not for any commercial purpose or for 18cee62800SMatthias Ringwald * monetary gain. 19cee62800SMatthias Ringwald * 20cee62800SMatthias Ringwald * THIS SOFTWARE IS PROVIDED BY BLUEKITCHEN GMBH AND CONTRIBUTORS 21cee62800SMatthias Ringwald * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22cee62800SMatthias Ringwald * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 23cee62800SMatthias Ringwald * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL MATTHIAS 24cee62800SMatthias Ringwald * RINGWALD OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 25cee62800SMatthias Ringwald * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 26cee62800SMatthias Ringwald * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 27cee62800SMatthias Ringwald * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 28cee62800SMatthias Ringwald * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 29cee62800SMatthias Ringwald * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 30cee62800SMatthias Ringwald * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31cee62800SMatthias Ringwald * SUCH DAMAGE. 32cee62800SMatthias Ringwald * 33cee62800SMatthias Ringwald * Please inquire about commercial licensing options at 34cee62800SMatthias Ringwald * [email protected] 35cee62800SMatthias Ringwald * 36cee62800SMatthias Ringwald */ 37cee62800SMatthias Ringwald 38e501bae0SMatthias Ringwald #define BTSTACK_FILE__ "spp_streamer_client.c" 3915de8206SMilanka Ringwald 4015de8206SMilanka Ringwald /* 4115de8206SMilanka Ringwald * spp_streamer_client.c 4215de8206SMilanka Ringwald */ 4315de8206SMilanka Ringwald 44cee62800SMatthias Ringwald // ***************************************************************************** 45cee62800SMatthias Ringwald /* EXAMPLE_START(spp_streamer_client): Client for SPP Streamer 46cee62800SMatthias Ringwald * 4758d7a529SMilanka Ringwald * @text Note: The SPP Streamer Client scans for and connects to SPP Streamer, 4858d7a529SMilanka Ringwald * and measures the throughput. 49cee62800SMatthias Ringwald */ 50cee62800SMatthias Ringwald // ***************************************************************************** 51cee62800SMatthias Ringwald 52cee62800SMatthias Ringwald #include <stdint.h> 53cee62800SMatthias Ringwald #include <stdio.h> 54cee62800SMatthias Ringwald #include <stdlib.h> 55cee62800SMatthias Ringwald #include <string.h> 56cee62800SMatthias Ringwald #include <inttypes.h> 57cee62800SMatthias Ringwald 58cee62800SMatthias Ringwald #include "btstack.h" 59cee62800SMatthias Ringwald 60*71a95af9SMatthias Ringwald // prototypes 61*71a95af9SMatthias Ringwald static void packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size); 62*71a95af9SMatthias Ringwald 63*71a95af9SMatthias Ringwald static uint8_t rfcomm_server_channel; 64cee62800SMatthias Ringwald 6583c12399SMatthias Ringwald #define NUM_ROWS 25 6683c12399SMatthias Ringwald #define NUM_COLS 40 6783c12399SMatthias Ringwald 68cee62800SMatthias Ringwald #define TEST_COD 0x1234 69cee62800SMatthias Ringwald 7083c12399SMatthias Ringwald #define TEST_MODE_SEND 1 7183c12399SMatthias Ringwald #define TEST_MODE_RECEIVE 2 7283c12399SMatthias Ringwald #define TEST_MODE_DUPLEX 3 7383c12399SMatthias Ringwald 7483c12399SMatthias Ringwald // configure test mode: send only, receive only, full duplex 7583c12399SMatthias Ringwald #define TEST_MODE TEST_MODE_SEND 7683c12399SMatthias Ringwald 77cee62800SMatthias Ringwald typedef enum { 78cee62800SMatthias Ringwald // SPP 79cee62800SMatthias Ringwald W4_PEER_COD, 80cee62800SMatthias Ringwald W4_SCAN_COMPLETE, 81cee62800SMatthias Ringwald W4_SDP_RESULT, 82cee62800SMatthias Ringwald W4_SDP_COMPLETE, 83cee62800SMatthias Ringwald W4_RFCOMM_CHANNEL, 84cee62800SMatthias Ringwald SENDING, 85cee62800SMatthias Ringwald DONE 86cee62800SMatthias Ringwald } state_t; 87cee62800SMatthias Ringwald 8883c12399SMatthias Ringwald static uint8_t test_data[NUM_ROWS * NUM_COLS]; 8983c12399SMatthias Ringwald static uint16_t spp_test_data_len; 9083c12399SMatthias Ringwald 91cee62800SMatthias Ringwald static btstack_packet_callback_registration_t hci_event_callback_registration; 92cee62800SMatthias Ringwald 93cee62800SMatthias Ringwald static bd_addr_t peer_addr; 94080ca4eeSMatthias Ringwald static state_t state; 95cee62800SMatthias Ringwald 96cee62800SMatthias Ringwald // SPP 97cee62800SMatthias Ringwald static uint16_t rfcomm_mtu; 98cee62800SMatthias Ringwald static uint16_t rfcomm_cid = 0; 99cee62800SMatthias Ringwald // static uint32_t data_to_send = DATA_VOLUME; 100cee62800SMatthias Ringwald 1018cef84f3SMatthias Ringwald /** 1028cef84f3SMatthias Ringwald * RFCOMM can make use for ERTM. Due to the need to re-transmit packets, 1038cef84f3SMatthias Ringwald * a large buffer is needed to still get high throughput 1048cef84f3SMatthias Ringwald */ 105278494d6SMatthias Ringwald #ifdef ENABLE_L2CAP_ENHANCED_RETRANSMISSION_MODE_FOR_RFCOMM 1068cef84f3SMatthias Ringwald static uint8_t ertm_buffer[20000]; 1078cef84f3SMatthias Ringwald static l2cap_ertm_config_t ertm_config = { 1088cef84f3SMatthias Ringwald 0, // ertm mandatory 1098cef84f3SMatthias Ringwald 8, // max transmit 1108cef84f3SMatthias Ringwald 2000, 1118cef84f3SMatthias Ringwald 12000, 1128cef84f3SMatthias Ringwald 1000, // l2cap ertm mtu 1138cef84f3SMatthias Ringwald 8, 1148cef84f3SMatthias Ringwald 8, 1158cef84f3SMatthias Ringwald 0, // No FCS 1168cef84f3SMatthias Ringwald }; 1178cef84f3SMatthias Ringwald static int ertm_buffer_in_use; 1188cef84f3SMatthias Ringwald static void rfcomm_ertm_request_handler(rfcomm_ertm_request_t * ertm_request){ 1198cef84f3SMatthias Ringwald printf("ERTM Buffer requested, buffer in use %u\n", ertm_buffer_in_use); 1208cef84f3SMatthias Ringwald if (ertm_buffer_in_use) return; 1218cef84f3SMatthias Ringwald ertm_buffer_in_use = 1; 1228cef84f3SMatthias Ringwald ertm_request->ertm_config = &ertm_config; 1238cef84f3SMatthias Ringwald ertm_request->ertm_buffer = ertm_buffer; 1248cef84f3SMatthias Ringwald ertm_request->ertm_buffer_size = sizeof(ertm_buffer); 1258cef84f3SMatthias Ringwald } 1268cef84f3SMatthias Ringwald static void rfcomm_ertm_released_handler(uint16_t ertm_id){ 1278cef84f3SMatthias Ringwald printf("ERTM Buffer released, buffer in use %u, ertm_id %x\n", ertm_buffer_in_use, ertm_id); 1288cef84f3SMatthias Ringwald ertm_buffer_in_use = 0; 1298cef84f3SMatthias Ringwald } 1308cef84f3SMatthias Ringwald #endif 131cee62800SMatthias Ringwald 132cee62800SMatthias Ringwald /** 133cee62800SMatthias Ringwald * Find remote peer by COD 134cee62800SMatthias Ringwald */ 135cee62800SMatthias Ringwald #define INQUIRY_INTERVAL 5 136cee62800SMatthias Ringwald static void start_scan(void){ 137cee62800SMatthias Ringwald printf("Starting inquiry scan..\n"); 138cee62800SMatthias Ringwald state = W4_PEER_COD; 139287c758dSMatthias Ringwald gap_inquiry_start(INQUIRY_INTERVAL); 140cee62800SMatthias Ringwald } 141cee62800SMatthias Ringwald static void stop_scan(void){ 142cee62800SMatthias Ringwald printf("Stopping inquiry scan..\n"); 143cee62800SMatthias Ringwald state = W4_SCAN_COMPLETE; 144287c758dSMatthias Ringwald gap_inquiry_stop(); 145cee62800SMatthias Ringwald } 146cee62800SMatthias Ringwald /* 147cee62800SMatthias Ringwald * @section Track throughput 148cee62800SMatthias Ringwald * @text We calculate the throughput by setting a start time and measuring the amount of 149cee62800SMatthias Ringwald * data sent. After a configurable REPORT_INTERVAL_MS, we print the throughput in kB/s 150cee62800SMatthias Ringwald * and reset the counter and start time. 151cee62800SMatthias Ringwald */ 152cee62800SMatthias Ringwald 153cee62800SMatthias Ringwald /* LISTING_START(tracking): Tracking throughput */ 154cee62800SMatthias Ringwald #define REPORT_INTERVAL_MS 3000 155cee62800SMatthias Ringwald static uint32_t test_data_transferred; 156cee62800SMatthias Ringwald static uint32_t test_data_start; 157cee62800SMatthias Ringwald 158cee62800SMatthias Ringwald static void test_reset(void){ 159cee62800SMatthias Ringwald test_data_start = btstack_run_loop_get_time_ms(); 160cee62800SMatthias Ringwald test_data_transferred = 0; 161cee62800SMatthias Ringwald } 162cee62800SMatthias Ringwald 163cee62800SMatthias Ringwald static void test_track_transferred(int bytes_sent){ 164cee62800SMatthias Ringwald test_data_transferred += bytes_sent; 165cee62800SMatthias Ringwald // evaluate 166cee62800SMatthias Ringwald uint32_t now = btstack_run_loop_get_time_ms(); 167cee62800SMatthias Ringwald uint32_t time_passed = now - test_data_start; 168cee62800SMatthias Ringwald if (time_passed < REPORT_INTERVAL_MS) return; 169cee62800SMatthias Ringwald // print speed 170cee62800SMatthias Ringwald int bytes_per_second = test_data_transferred * 1000 / time_passed; 171cee62800SMatthias Ringwald printf("%u bytes -> %u.%03u kB/s\n", (int) test_data_transferred, (int) bytes_per_second / 1000, bytes_per_second % 1000); 172cee62800SMatthias Ringwald 173cee62800SMatthias Ringwald // restart 174cee62800SMatthias Ringwald test_data_start = now; 175cee62800SMatthias Ringwald test_data_transferred = 0; 176cee62800SMatthias Ringwald } 177cee62800SMatthias Ringwald /* LISTING_END(tracking): Tracking throughput */ 178cee62800SMatthias Ringwald 17983c12399SMatthias Ringwald #if (TEST_MODE & TEST_MODE_SEND) 18083c12399SMatthias Ringwald static void spp_create_test_data(void){ 18183c12399SMatthias Ringwald int x,y; 18283c12399SMatthias Ringwald for (y=0;y<NUM_ROWS;y++){ 18383c12399SMatthias Ringwald for (x=0;x<NUM_COLS-2;x++){ 18483c12399SMatthias Ringwald test_data[y*NUM_COLS+x] = '0' + (x % 10); 18583c12399SMatthias Ringwald } 18683c12399SMatthias Ringwald test_data[y*NUM_COLS+NUM_COLS-2] = '\n'; 18783c12399SMatthias Ringwald test_data[y*NUM_COLS+NUM_COLS-1] = '\r'; 18883c12399SMatthias Ringwald } 18983c12399SMatthias Ringwald } 19083c12399SMatthias Ringwald static void spp_send_packet(void){ 19183c12399SMatthias Ringwald rfcomm_send(rfcomm_cid, (uint8_t*) test_data, spp_test_data_len); 19283c12399SMatthias Ringwald test_track_transferred(spp_test_data_len); 19383c12399SMatthias Ringwald rfcomm_request_can_send_now_event(rfcomm_cid); 19483c12399SMatthias Ringwald } 19583c12399SMatthias Ringwald #endif 19683c12399SMatthias Ringwald 197cee62800SMatthias Ringwald /* 198*71a95af9SMatthias Ringwald * @section SDP Query Packet Handler 199cee62800SMatthias Ringwald * 200*71a95af9SMatthias Ringwald * @text Store RFCOMM Channel for SPP service and initiates RFCOMM connection 201*71a95af9SMatthias Ringwald */ 202*71a95af9SMatthias Ringwald static void handle_query_rfcomm_event(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size){ 203*71a95af9SMatthias Ringwald UNUSED(packet_type); 204*71a95af9SMatthias Ringwald UNUSED(channel); 205*71a95af9SMatthias Ringwald UNUSED(size); 206*71a95af9SMatthias Ringwald 207*71a95af9SMatthias Ringwald switch (packet[0]){ 208*71a95af9SMatthias Ringwald case SDP_EVENT_QUERY_RFCOMM_SERVICE: 209*71a95af9SMatthias Ringwald rfcomm_server_channel = sdp_event_query_rfcomm_service_get_rfcomm_channel(packet); 210*71a95af9SMatthias Ringwald break; 211*71a95af9SMatthias Ringwald case SDP_EVENT_QUERY_COMPLETE: 212*71a95af9SMatthias Ringwald if (sdp_event_query_complete_get_status(packet)){ 213*71a95af9SMatthias Ringwald printf("SDP query failed 0x%02x\n", sdp_event_query_complete_get_status(packet)); 214*71a95af9SMatthias Ringwald break; 215*71a95af9SMatthias Ringwald } 216*71a95af9SMatthias Ringwald if (rfcomm_server_channel == 0){ 217*71a95af9SMatthias Ringwald printf("No SPP service found\n"); 218*71a95af9SMatthias Ringwald break; 219*71a95af9SMatthias Ringwald } 220*71a95af9SMatthias Ringwald printf("SDP query done, channel %u.\n", rfcomm_server_channel); 221*71a95af9SMatthias Ringwald rfcomm_create_channel(packet_handler, peer_addr, rfcomm_server_channel, NULL); 222*71a95af9SMatthias Ringwald break; 223*71a95af9SMatthias Ringwald } 224*71a95af9SMatthias Ringwald } 225*71a95af9SMatthias Ringwald 226*71a95af9SMatthias Ringwald /* 227*71a95af9SMatthias Ringwald * @section Gerenal Packet Handler 228*71a95af9SMatthias Ringwald * 229*71a95af9SMatthias Ringwald * @text Handles startup (BTSTACK_EVENT_STATE), inquiry, pairing, starts SDP query for SPP service, and RFCOMM connection 230cee62800SMatthias Ringwald */ 231cee62800SMatthias Ringwald 232cee62800SMatthias Ringwald static void packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size){ 233cee62800SMatthias Ringwald UNUSED(channel); 234cee62800SMatthias Ringwald 235cee62800SMatthias Ringwald bd_addr_t event_addr; 236cee62800SMatthias Ringwald uint8_t rfcomm_channel_nr; 237cee62800SMatthias Ringwald uint32_t class_of_device; 238cee62800SMatthias Ringwald 239cee62800SMatthias Ringwald switch (packet_type) { 240cee62800SMatthias Ringwald case HCI_EVENT_PACKET: 241cee62800SMatthias Ringwald switch (hci_event_packet_get_type(packet)) { 242cee62800SMatthias Ringwald 243cee62800SMatthias Ringwald case BTSTACK_EVENT_STATE: 244cee62800SMatthias Ringwald if (btstack_event_state_get_state(packet) != HCI_STATE_WORKING) return; 245cee62800SMatthias Ringwald start_scan(); 246cee62800SMatthias Ringwald break; 247cee62800SMatthias Ringwald 248cee62800SMatthias Ringwald case GAP_EVENT_INQUIRY_RESULT: 2497c03fe59SMatthias Ringwald if (state != W4_PEER_COD) break; 250cee62800SMatthias Ringwald class_of_device = gap_event_inquiry_result_get_class_of_device(packet); 251cee62800SMatthias Ringwald gap_event_inquiry_result_get_bd_addr(packet, event_addr); 252cee62800SMatthias Ringwald if (class_of_device == TEST_COD){ 253cee62800SMatthias Ringwald memcpy(peer_addr, event_addr, 6); 254cee62800SMatthias Ringwald printf("Peer found: %s\n", bd_addr_to_str(peer_addr)); 255cee62800SMatthias Ringwald stop_scan(); 256cee62800SMatthias Ringwald } else { 257cee62800SMatthias Ringwald printf("Device found: %s with COD: 0x%06x\n", bd_addr_to_str(event_addr), (int) class_of_device); 258cee62800SMatthias Ringwald } 259cee62800SMatthias Ringwald break; 260cee62800SMatthias Ringwald 261287c758dSMatthias Ringwald case GAP_EVENT_INQUIRY_COMPLETE: 2627c03fe59SMatthias Ringwald switch (state){ 2637c03fe59SMatthias Ringwald case W4_PEER_COD: 264cee62800SMatthias Ringwald printf("Inquiry complete\n"); 265cee62800SMatthias Ringwald printf("Peer not found, starting scan again\n"); 266cee62800SMatthias Ringwald start_scan(); 267cee62800SMatthias Ringwald break; 2687c03fe59SMatthias Ringwald case W4_SCAN_COMPLETE: 269*71a95af9SMatthias Ringwald printf("Start to connect and query for SPP service\n"); 2707c03fe59SMatthias Ringwald state = W4_RFCOMM_CHANNEL; 271*71a95af9SMatthias Ringwald sdp_client_query_rfcomm_channel_and_name_for_uuid(&handle_query_rfcomm_event, peer_addr, BLUETOOTH_ATTRIBUTE_PUBLIC_BROWSE_ROOT); 2727c03fe59SMatthias Ringwald break; 2737c03fe59SMatthias Ringwald default: 2747c03fe59SMatthias Ringwald break; 2757c03fe59SMatthias Ringwald } 2767c03fe59SMatthias Ringwald if (state == W4_PEER_COD){ 2777c03fe59SMatthias Ringwald } 2787c03fe59SMatthias Ringwald break; 279cee62800SMatthias Ringwald 28083c12399SMatthias Ringwald case HCI_EVENT_PIN_CODE_REQUEST: 28183c12399SMatthias Ringwald // inform about pin code request 28283c12399SMatthias Ringwald printf("Pin code request - using '0000'\n"); 28383c12399SMatthias Ringwald hci_event_pin_code_request_get_bd_addr(packet, event_addr); 28483c12399SMatthias Ringwald gap_pin_code_response(event_addr, "0000"); 28583c12399SMatthias Ringwald break; 28683c12399SMatthias Ringwald 28783c12399SMatthias Ringwald case HCI_EVENT_USER_CONFIRMATION_REQUEST: 28883c12399SMatthias Ringwald // inform about user confirmation request 28983c12399SMatthias Ringwald printf("SSP User Confirmation Request with numeric value '%06"PRIu32"'\n", little_endian_read_32(packet, 8)); 29083c12399SMatthias Ringwald printf("SSP User Confirmation Auto accept\n"); 29183c12399SMatthias Ringwald break; 29283c12399SMatthias Ringwald 29383c12399SMatthias Ringwald case RFCOMM_EVENT_INCOMING_CONNECTION: 29483c12399SMatthias Ringwald // data: event (8), len(8), address(48), channel (8), rfcomm_cid (16) 29583c12399SMatthias Ringwald rfcomm_event_incoming_connection_get_bd_addr(packet, event_addr); 29683c12399SMatthias Ringwald rfcomm_channel_nr = rfcomm_event_incoming_connection_get_server_channel(packet); 29783c12399SMatthias Ringwald rfcomm_cid = rfcomm_event_incoming_connection_get_rfcomm_cid(packet); 29883c12399SMatthias Ringwald printf("RFCOMM channel %u requested for %s\n", rfcomm_channel_nr, bd_addr_to_str(event_addr)); 29983c12399SMatthias Ringwald rfcomm_accept_connection(rfcomm_cid); 30083c12399SMatthias Ringwald break; 30183c12399SMatthias Ringwald 30283c12399SMatthias Ringwald case RFCOMM_EVENT_CHANNEL_OPENED: 30383c12399SMatthias Ringwald // data: event(8), len(8), status (8), address (48), server channel(8), rfcomm_cid(16), max frame size(16) 30483c12399SMatthias Ringwald if (rfcomm_event_channel_opened_get_status(packet)) { 30583c12399SMatthias Ringwald printf("RFCOMM channel open failed, status %u\n", rfcomm_event_channel_opened_get_status(packet)); 30683c12399SMatthias Ringwald } else { 30783c12399SMatthias Ringwald rfcomm_cid = rfcomm_event_channel_opened_get_rfcomm_cid(packet); 30883c12399SMatthias Ringwald rfcomm_mtu = rfcomm_event_channel_opened_get_max_frame_size(packet); 30983c12399SMatthias Ringwald printf("RFCOMM channel open succeeded. New RFCOMM Channel ID %u, max frame size %u\n", rfcomm_cid, rfcomm_mtu); 31083c12399SMatthias Ringwald test_reset(); 31183c12399SMatthias Ringwald 31283c12399SMatthias Ringwald // disable page/inquiry scan to get max performance 31383c12399SMatthias Ringwald gap_discoverable_control(0); 31483c12399SMatthias Ringwald gap_connectable_control(0); 31583c12399SMatthias Ringwald 31683c12399SMatthias Ringwald #if (TEST_MODE & TEST_MODE_SEND) 31783c12399SMatthias Ringwald // configure test data 31883c12399SMatthias Ringwald spp_test_data_len = rfcomm_mtu; 31983c12399SMatthias Ringwald if (spp_test_data_len > sizeof(test_data)){ 32083c12399SMatthias Ringwald spp_test_data_len = sizeof(test_data); 32183c12399SMatthias Ringwald } 32283c12399SMatthias Ringwald spp_create_test_data(); 32383c12399SMatthias Ringwald 32483c12399SMatthias Ringwald // start sending 32583c12399SMatthias Ringwald rfcomm_request_can_send_now_event(rfcomm_cid); 32683c12399SMatthias Ringwald #endif 32783c12399SMatthias Ringwald } 32883c12399SMatthias Ringwald break; 32983c12399SMatthias Ringwald 33083c12399SMatthias Ringwald #if (TEST_MODE & TEST_MODE_SEND) 33183c12399SMatthias Ringwald case RFCOMM_EVENT_CAN_SEND_NOW: 33283c12399SMatthias Ringwald spp_send_packet(); 33383c12399SMatthias Ringwald break; 33483c12399SMatthias Ringwald #endif 33583c12399SMatthias Ringwald 33683c12399SMatthias Ringwald case RFCOMM_EVENT_CHANNEL_CLOSED: 33783c12399SMatthias Ringwald printf("RFCOMM channel closed\n"); 33883c12399SMatthias Ringwald rfcomm_cid = 0; 33983c12399SMatthias Ringwald 34083c12399SMatthias Ringwald // re-enable page/inquiry scan again 34183c12399SMatthias Ringwald gap_discoverable_control(1); 34283c12399SMatthias Ringwald gap_connectable_control(1); 34383c12399SMatthias Ringwald break; 34483c12399SMatthias Ringwald 34583c12399SMatthias Ringwald 34683c12399SMatthias Ringwald 347cee62800SMatthias Ringwald default: 348cee62800SMatthias Ringwald break; 349cee62800SMatthias Ringwald } 350cee62800SMatthias Ringwald break; 351cee62800SMatthias Ringwald 352cee62800SMatthias Ringwald case RFCOMM_DATA_PACKET: 353cee62800SMatthias Ringwald test_track_transferred(size); 3547c03fe59SMatthias Ringwald 355cee62800SMatthias Ringwald #if 0 356cee62800SMatthias Ringwald printf("RCV: '"); 357cee62800SMatthias Ringwald for (i=0;i<size;i++){ 358cee62800SMatthias Ringwald putchar(packet[i]); 359cee62800SMatthias Ringwald } 360cee62800SMatthias Ringwald printf("'\n"); 361cee62800SMatthias Ringwald #endif 362cee62800SMatthias Ringwald break; 363cee62800SMatthias Ringwald 364cee62800SMatthias Ringwald default: 365cee62800SMatthias Ringwald break; 366cee62800SMatthias Ringwald } 367cee62800SMatthias Ringwald } 368cee62800SMatthias Ringwald 369cee62800SMatthias Ringwald /* 370cee62800SMatthias Ringwald * @section Main Application Setup 371cee62800SMatthias Ringwald * 372cee62800SMatthias Ringwald * @text As with the packet and the heartbeat handlers, the combined app setup contains the code from the individual example setups. 373cee62800SMatthias Ringwald */ 374cee62800SMatthias Ringwald 375cee62800SMatthias Ringwald 376cee62800SMatthias Ringwald /* LISTING_START(MainConfiguration): Init L2CAP RFCOMM SDO SM ATT Server and start heartbeat timer */ 377cee62800SMatthias Ringwald int btstack_main(int argc, const char * argv[]); 378cee62800SMatthias Ringwald int btstack_main(int argc, const char * argv[]){ 379cee62800SMatthias Ringwald UNUSED(argc); 380cee62800SMatthias Ringwald (void)argv; 381cee62800SMatthias Ringwald 382cee62800SMatthias Ringwald l2cap_init(); 383cee62800SMatthias Ringwald 384cee62800SMatthias Ringwald rfcomm_init(); 385cee62800SMatthias Ringwald 386278494d6SMatthias Ringwald #ifdef ENABLE_L2CAP_ENHANCED_RETRANSMISSION_MODE_FOR_RFCOMM 3878cef84f3SMatthias Ringwald // setup ERTM management 3888cef84f3SMatthias Ringwald rfcomm_enable_l2cap_ertm(&rfcomm_ertm_request_handler, &rfcomm_ertm_released_handler); 3898cef84f3SMatthias Ringwald #endif 3908cef84f3SMatthias Ringwald 391a4fe6467SMatthias Ringwald // register for HCI events 392a4fe6467SMatthias Ringwald hci_event_callback_registration.callback = &packet_handler; 393a4fe6467SMatthias Ringwald hci_add_event_handler(&hci_event_callback_registration); 394a4fe6467SMatthias Ringwald 395cee62800SMatthias Ringwald // init SDP 396cee62800SMatthias Ringwald gap_ssp_set_io_capability(SSP_IO_CAPABILITY_DISPLAY_YES_NO); 397cee62800SMatthias Ringwald 398cee62800SMatthias Ringwald // turn on! 399cee62800SMatthias Ringwald hci_power_control(HCI_POWER_ON); 400cee62800SMatthias Ringwald 401cee62800SMatthias Ringwald return 0; 402cee62800SMatthias Ringwald } 403cee62800SMatthias Ringwald /* LISTING_END */ 404cee62800SMatthias Ringwald /* EXAMPLE_END */ 405