125 lines
3.8 KiB
C
125 lines
3.8 KiB
C
|
#include <stdint.h>
|
||
|
#include <stdbool.h>
|
||
|
#include <stdlib.h>
|
||
|
#include <string.h>
|
||
|
|
||
|
|
||
|
#include "freertos/FreeRTOS.h"
|
||
|
#include "freertos/task.h"
|
||
|
|
||
|
#include "bt_app_common.h"
|
||
|
#include "bt_stack_manager.h"
|
||
|
#include "bt_sdp.h"
|
||
|
#include "bt_gap.h"
|
||
|
|
||
|
/* bta_api.h should not be included as BTA APIs should not be used by APP */
|
||
|
#include "bta_api.h"
|
||
|
|
||
|
typedef enum {
|
||
|
BT_APP_EVT_STACK_ON,
|
||
|
BT_APP_EVT_STACK_OFF,
|
||
|
BT_APP_EVT
|
||
|
} tBT_APP_EVT;
|
||
|
|
||
|
typedef union {
|
||
|
uint32_t dummy;
|
||
|
} tBT_APP_EVT_DATA;
|
||
|
|
||
|
static void bt_stack_state_changed(bt_state_t state);
|
||
|
static void bt_sdp_search_complete(bt_status_t status, bt_bdaddr_t *bd_addr, uint8_t* uuid, int num_records, bluetooth_sdp_record *records);
|
||
|
|
||
|
// static bt_bdaddr_t peer_bd_addr = {{0x00, 0x1b, 0xdc, 0x08, 0x0f, 0xe7}};
|
||
|
static bt_bdaddr_t peer_bd_addr = {{0xfc, 0x3f, 0x7c, 0xf1, 0x2c, 0x78}};
|
||
|
|
||
|
/* root browse
|
||
|
static const uint8_t target_uuid[16] = { 0x00, 0x00, 0x10, 0x02, 0x00, 0x00, 0x10, 0x00,
|
||
|
0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB };
|
||
|
*/
|
||
|
|
||
|
/* UUID_MAP_MAS */
|
||
|
static const uint8_t target_uuid[] = {0x00, 0x00, 0x11, 0x32, 0x00, 0x00, 0x10, 0x00,
|
||
|
0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB};
|
||
|
|
||
|
/* UUID AUDIO Source */
|
||
|
/*
|
||
|
static const uint8_t target_uuid[] = {0x00, 0x00, 0x11, 0x0A, 0x00, 0x00, 0x10, 0x00,
|
||
|
0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB};
|
||
|
*/
|
||
|
|
||
|
static bt_callbacks_t bt_callbacks = {
|
||
|
bt_stack_state_changed
|
||
|
};
|
||
|
|
||
|
static btsdp_callbacks_t btsdp_callbacks = {
|
||
|
bt_sdp_search_complete
|
||
|
};
|
||
|
|
||
|
static void bt_app_stack_evt(UINT16 event, char *p_param)
|
||
|
{
|
||
|
// tBT_APP_EVT_DATA *p_data = (tBT_APP_EVT_DATA *)p_param;
|
||
|
switch (event) {
|
||
|
case BT_APP_EVT_STACK_ON: {
|
||
|
// todo: BTM & BTA APIs should not be called in application task
|
||
|
char *dev_name = "SDP_CLIENT";
|
||
|
BTM_SetTraceLevel(BT_TRACE_LEVEL_DEBUG);
|
||
|
BTA_DmSetDeviceName(dev_name);
|
||
|
|
||
|
API_BT_GapSetScanMode(BT_SCAN_MODE_CONNECTABLE_DISCOVERABLE);
|
||
|
|
||
|
API_BT_SdpInit(&btsdp_callbacks);
|
||
|
|
||
|
vTaskDelay(20000/portTICK_PERIOD_MS);
|
||
|
API_BT_SdpSearch(&peer_bd_addr, target_uuid);
|
||
|
}
|
||
|
break;
|
||
|
default:
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
static void bt_stack_evt(tBT_APP_EVT event, tBT_APP_EVT_DATA *p_data)
|
||
|
{
|
||
|
LOG_ERROR("bt_stack_evt: %d\n", (uint16_t)event);
|
||
|
bt_app_transfer_context(bt_app_stack_evt, (uint16_t)event,
|
||
|
(void *)p_data, sizeof(tBT_APP_EVT_DATA), NULL);
|
||
|
}
|
||
|
|
||
|
static void bt_stack_state_changed(bt_state_t state)
|
||
|
{
|
||
|
if (state == BT_STATE_ON) {
|
||
|
bt_stack_evt(BT_APP_EVT_STACK_ON, NULL);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
static void bt_sdp_search_complete(bt_status_t status, bt_bdaddr_t *bd_addr, uint8_t* uuid, int num_records, bluetooth_sdp_record *records)
|
||
|
{
|
||
|
uint8_t *addr = bd_addr->address;
|
||
|
bluetooth_sdp_hdr_overlay *p = &records->mas.hdr;
|
||
|
LOG_ERROR("sdp search cmpl: st %d, bd_addr: %02x:%02x:%02x:%02x:%02x:%02x, records %d\n",
|
||
|
status, addr[0], addr[1], addr[2], addr[3], addr[4], addr[5], num_records);
|
||
|
if (p->service_name_length > 0) {
|
||
|
LOG_ERROR("service name: %s\n", p->service_name);
|
||
|
}
|
||
|
LOG_ERROR("rfc_chl_num %d, l2cap_psm %d, version %02x\n",
|
||
|
p->rfcomm_channel_number, p->l2cap_psm, p->profile_version);
|
||
|
#if 0
|
||
|
uint8_t *addr = bd_addr->address;
|
||
|
bluetooth_sdp_hdr_overlay *p = &records->hdr;
|
||
|
LOG_ERROR("sdp search cmpl: st %d, bd_addr: %02x:%02x:%02x:%02x:%02x:%02x, records %d, len:%d\n",
|
||
|
status, addr[0], addr[1], addr[2], addr[3], addr[4], addr[5], num_records, p->user1_ptr_len);
|
||
|
if (p->service_name_length > 0) {
|
||
|
LOG_ERROR("service name: %s\n", p->service_name);
|
||
|
}
|
||
|
#endif
|
||
|
}
|
||
|
|
||
|
void app_main_entry(void)
|
||
|
{
|
||
|
bt_status_t stat;
|
||
|
stat = API_BTDM_InitStack(&bt_callbacks);
|
||
|
if (stat == BT_STATUS_SUCCESS) {
|
||
|
API_BTDM_EnableStack();
|
||
|
}
|
||
|
}
|
||
|
|