/******************************************************************************* ** ** Function srvc_eng_init ** ** Description Initializa the GATT Service engine. ** *******************************************************************************/ tGATT_STATUS srvc_eng_init (void) { tBT_UUID app_uuid = {LEN_UUID_16, {UUID_SERVCLASS_DEVICE_INFO}}; if (srvc_eng_cb.enabled) { GATT_TRACE_ERROR0("DIS already initalized"); } else { memset(&srvc_eng_cb, 0, sizeof(tDIS_CB)); /* Create a GATT profile service */ srvc_eng_cb.gatt_if = GATT_Register(&app_uuid, &srvc_gatt_cback); GATT_StartIf(srvc_eng_cb.gatt_if); GATT_TRACE_DEBUG1 ("Srvc_Init: gatt_if=%d ", srvc_eng_cb.gatt_if); srvc_eng_cb.enabled = TRUE; //#if DIS_INCLUDED == TRUE dis_cb.dis_read_uuid_idx = 0xff; //#endif } return GATT_SUCCESS; }
bt_status_t btif_gattc_test_command_impl(uint16_t command, btgatt_test_params_t* params) { switch(command) { case 0x01: /* Enable */ { LOG_DEBUG(LOG_TAG, "%s: ENABLE - enable=%d", __FUNCTION__, params->u1); if (params->u1) { tBT_UUID app_uuid = {LEN_UUID_128,{0xAE}}; test_cb.gatt_if = GATT_Register(&app_uuid, &btif_test_callbacks); GATT_StartIf(test_cb.gatt_if); } else { GATT_Deregister(test_cb.gatt_if); test_cb.gatt_if = 0; } break; } case 0x02: /* Connect */ { LOG_DEBUG(LOG_TAG, "%s: CONNECT - device=%02x:%02x:%02x:%02x:%02x:%02x (dev_type=%d, addr_type=%d)", __FUNCTION__, params->bda1->address[0], params->bda1->address[1], params->bda1->address[2], params->bda1->address[3], params->bda1->address[4], params->bda1->address[5], params->u1, params->u2); if (params->u1 == BT_DEVICE_TYPE_BLE) BTM_SecAddBleDevice(params->bda1->address, NULL, BT_DEVICE_TYPE_BLE, params->u2); if ( !GATT_Connect(test_cb.gatt_if, params->bda1->address, TRUE, BT_TRANSPORT_LE) ) { LOG_ERROR(LOG_TAG, "%s: GATT_Connect failed!", __FUNCTION__); } break; } case 0x03: /* Disconnect */ { LOG_DEBUG(LOG_TAG, "%s: DISCONNECT - conn_id=%d", __FUNCTION__, test_cb.conn_id); GATT_Disconnect(test_cb.conn_id); break; } case 0x04: /* Discover */ { char buf[50] = {0}; tGATT_DISC_PARAM param; memset(¶m, 0, sizeof(tGATT_DISC_PARAM)); if (params->u1 >= GATT_DISC_MAX) { LOG_ERROR(LOG_TAG, "%s: DISCOVER - Invalid type (%d)!", __FUNCTION__, params->u1); return 0; } param.s_handle = params->u2; param.e_handle = params->u3; btif_to_bta_uuid(¶m.service, params->uuid1); LOG_DEBUG(LOG_TAG, "%s: DISCOVER (%s), conn_id=%d, uuid=%s, handles=0x%04x-0x%04x", __FUNCTION__, disc_name[params->u1], test_cb.conn_id, format_uuid(param.service, buf), params->u2, params->u3); GATTC_Discover(test_cb.conn_id, params->u1, ¶m); break; } case 0xF0: /* Pairing configuration */ LOG_DEBUG(LOG_TAG, "%s: Setting pairing config auth=%d, iocaps=%d, keys=%d/%d/%d", __FUNCTION__, params->u1, params->u2, params->u3, params->u4, params->u5); bte_appl_cfg.ble_auth_req = params->u1; bte_appl_cfg.ble_io_cap = params->u2; bte_appl_cfg.ble_init_key = params->u3; bte_appl_cfg.ble_resp_key = params->u4; bte_appl_cfg.ble_max_key_size = params->u5; break; default: LOG_ERROR(LOG_TAG, "%s: UNKNOWN TEST COMMAND 0x%02x", __FUNCTION__, command); break; } return 0; }
/******************************************************************************* ** ** Function btm_ble_att_db_init ** ** Description GAP ATT database initalization. ** ** Returns void. ** *******************************************************************************/ void gap_attr_db_init(void) { tBT_UUID app_uuid = {LEN_UUID_128,{0}}; tBT_UUID uuid = {LEN_UUID_16,{UUID_SERVCLASS_GAP_SERVER}}; UINT16 service_handle; tGAP_ATTR *p_db_attr = &gap_cb.gatt_attr[0]; tGATT_STATUS status; /* Fill our internal UUID with a fixed pattern 0x82 */ memset (&app_uuid.uu.uuid128, 0x82, LEN_UUID_128); memset(gap_cb.gatt_attr, 0, sizeof(tGAP_ATTR) *GAP_MAX_CHAR_NUM); gap_cb.gatt_if = GATT_Register(&app_uuid, &gap_cback); GATT_StartIf(gap_cb.gatt_if); /* Create a GAP service */ service_handle = GATTS_CreateService (gap_cb.gatt_if, &uuid, 0, GAP_MAX_ATTR_NUM, TRUE); GAP_TRACE_EVENT ("gap_attr_db_init service_handle = %d", service_handle); /* add Device Name Characteristic */ uuid.len = LEN_UUID_16; uuid.uu.uuid16 = p_db_attr->uuid = GATT_UUID_GAP_DEVICE_NAME; p_db_attr->handle = GATTS_AddCharacteristic(service_handle, &uuid, GATT_PERM_READ, GATT_CHAR_PROP_BIT_READ); p_db_attr ++; /* add Icon characteristic */ uuid.uu.uuid16 = p_db_attr->uuid = GATT_UUID_GAP_ICON; p_db_attr->handle = GATTS_AddCharacteristic(service_handle, &uuid, GATT_PERM_READ, GATT_CHAR_PROP_BIT_READ); p_db_attr ++; #if BTM_PERIPHERAL_ENABLED == TRUE /* Only needed for peripheral testing */ /* add preferred connection parameter characteristic */ uuid.uu.uuid16 = p_db_attr->uuid = GATT_UUID_GAP_PREF_CONN_PARAM; p_db_attr->attr_value.conn_param.int_max = GAP_PREFER_CONN_INT_MAX; /* 6 */ p_db_attr->attr_value.conn_param.int_min = GAP_PREFER_CONN_INT_MIN; /* 0 */ p_db_attr->attr_value.conn_param.latency = GAP_PREFER_CONN_LATENCY; /* 0 */ p_db_attr->attr_value.conn_param.sp_tout = GAP_PREFER_CONN_SP_TOUT; /* 2000 */ p_db_attr->handle = GATTS_AddCharacteristic(service_handle, &uuid, GATT_PERM_READ, GATT_CHAR_PROP_BIT_READ); p_db_attr ++; #endif /* start service now */ memset (&app_uuid.uu.uuid128, 0x81, LEN_UUID_128); status = GATTS_StartService(gap_cb.gatt_if, service_handle, GAP_TRANSPORT_SUPPORTED ); GAP_TRACE_EVENT ("GAP App gatt_if: %d s_hdl = %d start_status=%d", gap_cb.gatt_if, service_handle, status); }