Satish kumar sugasi | da90009 | 2014-02-06 19:30:27 -0800 | [diff] [blame] | 1 | /* |
Nitin Shivpure | 2906055 | 2014-09-10 11:28:06 +0530 | [diff] [blame] | 2 | * Copyright (c) 2013, The Linux Foundation. All rights reserved. |
Satish kumar sugasi | da90009 | 2014-02-06 19:30:27 -0800 | [diff] [blame] | 3 | * |
| 4 | * Redistribution and use in source and binary forms, with or without |
| 5 | * modification, are permitted provided that the following conditions are met: |
| 6 | * * Redistributions of source code must retain the above copyright |
| 7 | * notice, this list of conditions and the following disclaimer. |
| 8 | * * Redistributions in binary form must reproduce the above copyright |
| 9 | * notice, this list of conditions and the following disclaimer in the |
| 10 | * documentation and/or other materials provided with the distribution. |
| 11 | * * Neither the name of The Linux Foundation nor |
| 12 | * the names of its contributors may be used to endorse or promote |
| 13 | * products derived from this software without specific prior written |
| 14 | * permission. |
| 15 | * |
| 16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 18 | * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| 19 | * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR |
| 20 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| 21 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 22 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; |
| 23 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| 24 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR |
| 25 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
| 26 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | */ |
| 28 | |
| 29 | /************************************************************************************ |
| 30 | * |
| 31 | * Filename: gatt_tool.c |
| 32 | * |
| 33 | * Description: Bluedroid GATT TOOL application |
| 34 | * |
| 35 | ***********************************************************************************/ |
| 36 | |
| 37 | #include <stdio.h> |
| 38 | #include <stdint.h> |
| 39 | #include <dlfcn.h> |
| 40 | #include <stdlib.h> |
| 41 | #include <errno.h> |
| 42 | #include <string.h> |
| 43 | #include <pthread.h> |
| 44 | #include <unistd.h> |
| 45 | #include <ctype.h> |
| 46 | #include <fcntl.h> |
| 47 | #include <sys/prctl.h> |
| 48 | #include <sys/capability.h> |
| 49 | #include "l2c_api.h" |
| 50 | |
| 51 | #include <arpa/inet.h> |
| 52 | #include <netinet/in.h> |
| 53 | #include <netdb.h> |
| 54 | |
| 55 | #include <private/android_filesystem_config.h> |
| 56 | #include <android/log.h> |
| 57 | |
| 58 | #include <hardware/hardware.h> |
| 59 | #include <hardware/bluetooth.h> |
| 60 | #include <hardware/bt_gatt.h> |
| 61 | #include <hardware/bt_gatt_client.h> |
| 62 | #include <hardware/bt_gatt_server.h> |
| 63 | #include <hardware/bt_gatt_types.h> |
| 64 | #include <bt_testapp.h> |
| 65 | |
| 66 | #ifdef TEST_APP_INTERFACE |
| 67 | /************************************************************************************ |
| 68 | ** Constants & Macros |
| 69 | ************************************************************************************/ |
| 70 | |
| 71 | |
| 72 | #ifndef TRUE |
| 73 | #define TRUE 1 |
| 74 | #endif |
| 75 | #ifndef FALSE |
| 76 | #define FALSE 0 |
| 77 | #endif |
| 78 | |
| 79 | #define PID_FILE "/data/.bdt_pid" |
| 80 | |
| 81 | #ifndef MAX |
| 82 | #define MAX(x, y) ((x) > (y) ? (x) : (y)) |
| 83 | #endif |
| 84 | |
| 85 | #define CASE_RETURN_STR(const) case const: return #const; |
| 86 | |
| 87 | /************************************************************************************ |
| 88 | ** Local type definitions |
| 89 | ************************************************************************************/ |
| 90 | static void register_client_cb(int status, int client_if, bt_uuid_t *app_uuid); |
| 91 | static void scan_result_cb(bt_bdaddr_t* remote_bd_addr, int rssi, uint8_t* adv_data); |
| 92 | static void listen_cb(int status, int server_if); |
| 93 | |
| 94 | static void register_server_cb(int status, int server_if, bt_uuid_t *app_uuid); |
| 95 | |
| 96 | |
| 97 | /************************************************************************************ |
| 98 | ** Static variables |
| 99 | ************************************************************************************/ |
| 100 | |
| 101 | static unsigned char main_done = 0; |
| 102 | static bt_status_t status; |
| 103 | |
| 104 | /* Main API */ |
| 105 | static bluetooth_device_t* bt_device; |
| 106 | |
| 107 | const bt_interface_t* sBtInterface = NULL; |
| 108 | |
| 109 | static gid_t groups[] = { AID_NET_BT, AID_INET, AID_NET_BT_ADMIN, |
| 110 | AID_SYSTEM, AID_MISC, AID_SDCARD_RW, |
| 111 | AID_NET_ADMIN, AID_VPN}; |
| 112 | |
| 113 | enum { |
| 114 | DISCONNECT, |
| 115 | CONNECTING, |
| 116 | CONNECTED, |
| 117 | DISCONNECTING |
| 118 | }; |
| 119 | static unsigned char bt_enabled = 0; |
| 120 | static int g_ConnectionState = DISCONNECT; |
| 121 | static int g_AdapterState = BT_STATE_OFF; |
| 122 | static int g_PairState = BT_BOND_STATE_NONE; |
| 123 | |
| 124 | |
| 125 | static int g_conn_id = 0; |
| 126 | static int g_client_if = 0; |
| 127 | static int g_server_if = 0; |
| 128 | static int g_client_if_scan = 0; |
| 129 | static int g_server_if_scan = 0; |
| 130 | |
Nitin Shivpure | 2906055 | 2014-09-10 11:28:06 +0530 | [diff] [blame] | 131 | const btgatt_test_interface_t *sGattInterface = NULL; |
Satish kumar sugasi | da90009 | 2014-02-06 19:30:27 -0800 | [diff] [blame] | 132 | const btgatt_interface_t *sGattIfaceScan = NULL; |
flintman | fb976bd | 2015-10-02 19:10:17 -0400 | [diff] [blame] | 133 | #if SMP_INCLUDED == TRUE |
Nitin Shivpure | 2906055 | 2014-09-10 11:28:06 +0530 | [diff] [blame] | 134 | const btsmp_interface_t *sSmpIface = NULL; |
flintman | fb976bd | 2015-10-02 19:10:17 -0400 | [diff] [blame] | 135 | #endif |
Nitin Shivpure | 2906055 | 2014-09-10 11:28:06 +0530 | [diff] [blame] | 136 | const btgap_interface_t *sGapInterface = NULL; |
Satish kumar sugasi | da90009 | 2014-02-06 19:30:27 -0800 | [diff] [blame] | 137 | const btl2cap_interface_t *sL2capInterface = NULL; |
| 138 | |
| 139 | |
| 140 | int Btif_gatt_layer = TRUE; |
| 141 | bt_bdaddr_t *remote_bd_address; |
| 142 | |
| 143 | static UINT16 g_SecLevel = 0; |
| 144 | static BOOLEAN g_ConnType = TRUE;//DUT is initiating connection |
| 145 | static BOOLEAN g_Fcr_Present = FALSE; |
| 146 | static UINT8 g_Fcr_Mode = L2CAP_FCR_BASIC_MODE; |
| 147 | static UINT8 g_Ertm_AllowedMode = (L2CAP_FCR_CHAN_OPT_BASIC | L2CAP_FCR_CHAN_OPT_ERTM | L2CAP_FCR_CHAN_OPT_STREAM); |
| 148 | static int g_LocalBusy = 0; |
| 149 | |
| 150 | |
| 151 | /* Default mtu */ |
| 152 | static int g_imtu = 672; |
| 153 | static int g_omtu = 0; |
| 154 | |
| 155 | /* Default FCS option */ |
| 156 | static int g_fcs = 0x01; |
| 157 | |
| 158 | /* Default data size */ |
| 159 | static long data_size = -1; |
| 160 | static long buffer_size = 2048; |
| 161 | static unsigned short cid = 0; |
| 162 | |
| 163 | enum { |
| 164 | L2CAP_NOT_CONNECTED, |
| 165 | L2CAP_CONN_SETUP, |
| 166 | L2CAP_CONNECTED |
| 167 | }; |
| 168 | |
| 169 | static int L2cap_conn_state = L2CAP_NOT_CONNECTED; |
| 170 | static tL2CAP_CFG_INFO tl2cap_cfg_info = {0}; |
| 171 | static UINT16 g_PSM = 0; |
| 172 | static UINT16 g_lcid = 0; |
| 173 | |
| 174 | |
| 175 | enum { |
| 176 | SEND, |
| 177 | RECEIVE, |
| 178 | WAITANDSEND, |
| 179 | PAIR, |
| 180 | PING, |
| 181 | CONNECT, |
| 182 | }; |
| 183 | |
| 184 | |
| 185 | /* Control channel eL2CAP default options */ |
| 186 | tL2CAP_FCR_OPTS ertm_fcr_opts_def = { |
| 187 | L2CAP_FCR_ERTM_MODE, |
| 188 | 3, /* Tx window size */ |
| 189 | MCA_FCR_OPT_MAX_TX_B4_DISCNT, /* Maximum transmissions before disconnecting */ |
| 190 | 2000, /* Retransmission timeout (2 secs) */ |
| 191 | MCA_FCR_OPT_MONITOR_TOUT, /* Monitor timeout (12 secs) */ |
| 192 | 100 /* MPS segment size */ |
| 193 | }; |
| 194 | |
| 195 | tL2CAP_FCR_OPTS stream_fcr_opts_def = { |
| 196 | L2CAP_FCR_STREAM_MODE, |
| 197 | 3,/* Tx window size */ |
| 198 | MCA_FCR_OPT_MAX_TX_B4_DISCNT, /* Maximum transmissions before disconnecting */ |
| 199 | 2000, /* Retransmission timeout (2 secs) */ |
| 200 | MCA_FCR_OPT_MONITOR_TOUT, /* Monitor timeout (12 secs) */ |
| 201 | 100 /* MPS segment size */ |
| 202 | }; |
| 203 | static tL2CAP_ERTM_INFO t_ertm_info = {0}; |
| 204 | |
| 205 | |
| 206 | /************************************************************************************ |
| 207 | ** Static functions |
| 208 | ************************************************************************************/ |
| 209 | |
| 210 | static void process_cmd(char *p, unsigned char is_job); |
| 211 | static void job_handler(void *param); |
| 212 | static void bdt_log(const char *fmt_str, ...); |
| 213 | static void l2c_connect(bt_bdaddr_t *bd_addr); |
| 214 | static UINT16 do_l2cap_connect(bt_bdaddr_t * bd_addr); |
| 215 | |
| 216 | |
| 217 | |
| 218 | int GetBdAddr(char *p, bt_bdaddr_t *pbd_addr); |
| 219 | |
| 220 | |
| 221 | /************************************************************************************ |
| 222 | ** GATT Client Callbacks |
| 223 | ************************************************************************************/ |
| 224 | static void register_client_cb(int status, int client_if, bt_uuid_t *app_uuid) |
| 225 | { |
| 226 | printf("%s:: status=%d, client_if=%d, uuid=%02x%02x%02x%02x %02x%02x%02x%02x %02x%02x%02x%02x %02x%02x%02x%02x \n", __FUNCTION__, status, client_if, |
| 227 | app_uuid->uu[0], app_uuid->uu[1], app_uuid->uu[2], app_uuid->uu[3], |
| 228 | app_uuid->uu[4], app_uuid->uu[5], app_uuid->uu[6], app_uuid->uu[7], |
| 229 | app_uuid->uu[8], app_uuid->uu[9], app_uuid->uu[10], app_uuid->uu[11], |
| 230 | app_uuid->uu[12], app_uuid->uu[13], app_uuid->uu[14], app_uuid->uu[15]); |
| 231 | if(0 == status) g_client_if_scan = client_if; |
| 232 | } |
| 233 | |
| 234 | static void scan_result_cb(bt_bdaddr_t* remote_bd_addr, int rssi, uint8_t* adv_data) |
| 235 | { |
| 236 | printf("%s:: remote_bd_addr=%02x:%02x:%02x:%02x:%02x:%02x, adv_data=0x%x \n", __FUNCTION__, |
| 237 | remote_bd_addr->address[0], remote_bd_addr->address[1], remote_bd_addr->address[2], |
| 238 | remote_bd_addr->address[3], remote_bd_addr->address[4], remote_bd_addr->address[5], *adv_data); |
| 239 | } |
| 240 | |
| 241 | static void connect_cb(int conn_id, int status, int client_if, bt_bdaddr_t* remote_bd_addr) |
| 242 | { |
| 243 | printf("%s:: remote_bd_addr=%02x:%02x:%02x:%02x:%02x:%02x, conn_id=0x%x, status=%d, client_if=%d\n", __FUNCTION__, |
| 244 | remote_bd_addr->address[0], remote_bd_addr->address[1], remote_bd_addr->address[2], |
| 245 | remote_bd_addr->address[3], remote_bd_addr->address[4], remote_bd_addr->address[5], conn_id, status, client_if); |
| 246 | |
| 247 | g_conn_id = conn_id; |
| 248 | sGapInterface->Gap_BleAttrDBUpdate(remote_bd_addr->address, 50, 70, 0, 1000); |
| 249 | |
| 250 | } |
| 251 | |
| 252 | static void register_for_notification_cb(int conn_id, int registered, int status, btgatt_srvc_id_t *srvc_id, btgatt_gatt_id_t *char_id) |
| 253 | { |
| 254 | printf("%s:: conn_id=%d, registered=%d, status=%d \n", __FUNCTION__, conn_id, registered, status); |
| 255 | } |
| 256 | static void listen_cb(int status, int server_if) |
| 257 | { |
| 258 | printf("%s:: status=%d, server_if=%d \n", __FUNCTION__, status, server_if); |
| 259 | if(0 == status) g_server_if = server_if; |
| 260 | } |
| 261 | |
| 262 | static btgatt_client_callbacks_t sGattClient_cb = |
| 263 | { |
| 264 | register_client_cb, |
| 265 | scan_result_cb, |
| 266 | connect_cb, |
| 267 | NULL, |
| 268 | NULL, |
| 269 | NULL, |
| 270 | NULL, |
| 271 | NULL, |
| 272 | NULL, |
| 273 | NULL, //register_for_notification_cb, |
| 274 | NULL, |
| 275 | NULL, |
| 276 | NULL, |
| 277 | NULL, |
| 278 | NULL, |
| 279 | NULL, |
| 280 | NULL, |
| 281 | listen_cb, |
| 282 | NULL, |
| 283 | NULL, |
| 284 | NULL, |
| 285 | NULL, |
| 286 | NULL, |
Nitin Shivpure | 2906055 | 2014-09-10 11:28:06 +0530 | [diff] [blame] | 287 | NULL, |
| 288 | NULL, |
| 289 | NULL, |
| 290 | NULL, |
| 291 | NULL, |
| 292 | NULL, |
| 293 | NULL, |
| 294 | NULL, |
Satish kumar sugasi | da90009 | 2014-02-06 19:30:27 -0800 | [diff] [blame] | 295 | NULL |
| 296 | }; |
| 297 | |
| 298 | |
| 299 | /************************************************************************************ |
| 300 | ** GATT Server Callbacks |
| 301 | ************************************************************************************/ |
| 302 | static void register_server_cb(int status, int server_if, bt_uuid_t *app_uuid) |
| 303 | { |
| 304 | printf("%s:: status=%d, server_if=%d \n", __FUNCTION__, status, server_if); |
| 305 | if(0 == status) g_server_if_scan = server_if; |
| 306 | } |
| 307 | |
| 308 | static void server_connection_cb(int conn_id, int server_if, int connected, bt_bdaddr_t *bda) |
| 309 | { |
| 310 | printf("%s:: conn_id=%d, server_if=%d \n", __FUNCTION__, conn_id, server_if); |
| 311 | g_conn_id = conn_id; |
| 312 | } |
| 313 | |
| 314 | static btgatt_server_callbacks_t sGattServer_cb = |
| 315 | { |
| 316 | register_server_cb, |
| 317 | server_connection_cb, //connection_callback connection_cb; |
| 318 | NULL, //service_added_callback service_added_cb; |
| 319 | NULL, //included_service_added_callback included_service_added_cb; |
| 320 | NULL, //characteristic_added_callback characteristic_added_cb; |
| 321 | NULL, //descriptor_added_callback descriptor_added_cb; |
| 322 | NULL, //service_started_callback service_started_cb; |
| 323 | NULL, //service_stopped_callback service_stopped_cb; |
| 324 | NULL, //service_deleted_callback service_deleted_cb; |
| 325 | NULL, //request_read_callback request_read_cb; |
| 326 | NULL, //request_write_callback request_write_cb; |
| 327 | NULL, //request_exec_write_callback request_exec_write_cb; |
| 328 | NULL, //response_confirmation_callback response_confirmation_cb; |
Nitin Shivpure | 2906055 | 2014-09-10 11:28:06 +0530 | [diff] [blame] | 329 | NULL, |
Sridhar Gujje | 876c69b | 2015-02-20 15:55:44 +0530 | [diff] [blame] | 330 | NULL, |
Nitin Shivpure | 2906055 | 2014-09-10 11:28:06 +0530 | [diff] [blame] | 331 | NULL |
Satish kumar sugasi | da90009 | 2014-02-06 19:30:27 -0800 | [diff] [blame] | 332 | }; |
| 333 | |
| 334 | |
| 335 | /************************************************************************************ |
| 336 | ** GATT Callbacks |
| 337 | ************************************************************************************/ |
| 338 | static void DiscoverRes_cb (UINT16 conn_id, tGATT_DISC_TYPE disc_type, tGATT_DISC_RES *p_data) |
| 339 | { |
| 340 | printf("%s:: conn_id=%d, disc_type=%d\n", __FUNCTION__, conn_id, disc_type); |
| 341 | } |
| 342 | |
| 343 | static void DiscoverCmpl_cb (UINT16 conn_id, tGATT_DISC_TYPE disc_type, tGATT_STATUS status) |
| 344 | { |
| 345 | printf("%s:: conn_id=%d, disc_type=%d, status=%d\n", __FUNCTION__, conn_id, disc_type, status); |
| 346 | } |
| 347 | |
| 348 | static void OperationCmpl_cb(UINT16 conn_id, tGATTC_OPTYPE op, tGATT_STATUS status, tGATT_CL_COMPLETE *p_data) |
| 349 | { |
| 350 | printf("%s:: conn_id=%d, op=%d, status=%d\n", __FUNCTION__, conn_id, op, status); |
| 351 | } |
| 352 | |
| 353 | static void Connection_cb (tGATT_IF gatt_if, BD_ADDR bda, UINT16 conn_id, BOOLEAN connected, tGATT_DISCONN_REASON reason,tBT_TRANSPORT transport) |
| 354 | { |
| 355 | printf("%s:: remote_bd_addr=%02x:%02x:%02x:%02x:%02x:%02x, conn_id=0x%x, connected=%d, reason=%d, gatt_if=%d \n", __FUNCTION__, |
| 356 | bda[0], bda[1], bda[2], bda[3], bda[4], bda[5], |
| 357 | conn_id, connected, reason, gatt_if); |
| 358 | g_conn_id = conn_id; |
| 359 | } |
| 360 | |
| 361 | static void AttributeReq_cb(UINT16 conn_id, UINT32 trans_id, tGATTS_REQ_TYPE type, tGATTS_DATA *p_data) |
| 362 | { |
| 363 | printf("%s:: conn_id=%d, trans_id=%d, type=%u\n", __FUNCTION__, conn_id, trans_id, type); |
| 364 | } |
| 365 | |
| 366 | |
| 367 | static tGATT_CBACK sGattCB = |
| 368 | { |
| 369 | Connection_cb, |
| 370 | OperationCmpl_cb, |
| 371 | DiscoverRes_cb, |
| 372 | DiscoverCmpl_cb, |
| 373 | AttributeReq_cb, |
Nitin Shivpure | 2906055 | 2014-09-10 11:28:06 +0530 | [diff] [blame] | 374 | NULL, |
Satish kumar sugasi | da90009 | 2014-02-06 19:30:27 -0800 | [diff] [blame] | 375 | NULL |
| 376 | }; |
| 377 | |
| 378 | /************************************************************************************ |
| 379 | ** GAP Callbacks |
| 380 | ************************************************************************************/ |
| 381 | |
| 382 | static void gap_ble_s_attr_request_cback (UINT16 conn_id, UINT32 trans_id, tGATTS_REQ_TYPE op_code, tGATTS_DATA *p_data) |
| 383 | { |
| 384 | printf("%s:: conn_id=%d, trans_id=%d, op_code=%u\n", __FUNCTION__, conn_id, trans_id, op_code); |
| 385 | } |
| 386 | |
| 387 | /* client connection callback */ |
| 388 | static void gap_ble_c_connect_cback (tGATT_IF gatt_if, BD_ADDR bda, UINT16 conn_id, BOOLEAN connected, tGATT_DISCONN_REASON reason,tBT_TRANSPORT transport) |
| 389 | { |
| 390 | printf("%s:: gatt_if=%d, remote_bd_addr=%02x:%02x:%02x:%02x:%02x:%02x, conn_id=%d, connected=%d, reason=%d\n", __FUNCTION__, |
| 391 | gatt_if, bda[0], bda[1], bda[2], bda[3], bda[4], bda[5], conn_id, connected, reason); |
| 392 | g_conn_id = conn_id; |
| 393 | } |
| 394 | static void gap_ble_c_cmpl_cback (UINT16 conn_id, tGATTC_OPTYPE op, tGATT_STATUS status, tGATT_CL_COMPLETE *p_data) |
| 395 | { |
| 396 | printf("%s:: conn_id=%d, op=%d, status=%d\n", __FUNCTION__, conn_id, op, status); |
| 397 | } |
| 398 | |
| 399 | static tGATT_CBACK gap_cback = |
| 400 | { |
| 401 | gap_ble_c_connect_cback, |
| 402 | gap_ble_c_cmpl_cback, |
| 403 | NULL, |
| 404 | NULL, |
| 405 | gap_ble_s_attr_request_cback, |
Nitin Shivpure | 2906055 | 2014-09-10 11:28:06 +0530 | [diff] [blame] | 406 | NULL, |
Satish kumar sugasi | da90009 | 2014-02-06 19:30:27 -0800 | [diff] [blame] | 407 | NULL |
| 408 | }; |
| 409 | |
| 410 | |
flintman | fb976bd | 2015-10-02 19:10:17 -0400 | [diff] [blame] | 411 | #if SMP_INCLUDED == TRUE |
Satish kumar sugasi | da90009 | 2014-02-06 19:30:27 -0800 | [diff] [blame] | 412 | /************************************************************************************ |
| 413 | ** SMP Callbacks |
| 414 | ************************************************************************************/ |
| 415 | static UINT8 SMP_cb (tSMP_EVT event, BD_ADDR bda, tSMP_EVT_DATA *p_data) |
| 416 | { |
| 417 | printf("%s:: event=%d(1-SMP_IO_CAP_REQ_EVT, 2-SMP_SEC_REQUEST_EVT, \ |
| 418 | 3-SMP_PASSKEY_NOTIF_EVT, 4-SMP_PASSKEY_REQ_EVT, 6-SMP_COMPLT_EVT), \ |
| 419 | \nremote_bd_addr=%02x:%02x:%02x:%02x:%02x:%02x, PassKey=%u \n", __FUNCTION__, event, |
| 420 | bda[0], bda[1], bda[2], bda[3], bda[4], bda[5], p_data->passkey); |
| 421 | switch(event) |
| 422 | { |
| 423 | case SMP_IO_CAP_REQ_EVT: |
| 424 | printf("Io_Caps=%d, auth_req=%d, max_key_size=%d, init_keys=%d, resp_keys=%d \n", p_data->io_req.io_cap, p_data->io_req.auth_req, p_data->io_req.max_key_size, p_data->io_req.init_keys, p_data->io_req.resp_keys); |
| 425 | break; |
| 426 | |
| 427 | case SMP_PASSKEY_REQ_EVT: |
| 428 | case SMP_PASSKEY_NOTIF_EVT: |
| 429 | printf("passkey value=%u\n", p_data->passkey); |
| 430 | sSmpIface->PasskeyReply(bda, SMP_SUCCESS, p_data->passkey); |
| 431 | break; |
| 432 | case SMP_OOB_REQ_EVT: |
| 433 | //p_dev_rec->sec_flags |= BTM_SEC_LINK_KEY_AUTHED; |
| 434 | break; |
| 435 | case SMP_SEC_REQUEST_EVT: |
| 436 | case SMP_COMPLT_EVT: |
| 437 | printf("SMP Complete Event:: Reason=%d \n", p_data->cmplt.reason); |
| 438 | if(p_data->cmplt.reason == SMP_SUCCESS) |
| 439 | { |
| 440 | sSmpIface->SecurityGrant(bda, p_data->cmplt.reason); |
| 441 | printf("Granting Security \n"); |
| 442 | } |
| 443 | break; |
| 444 | } |
| 445 | return 0; |
| 446 | } |
flintman | fb976bd | 2015-10-02 19:10:17 -0400 | [diff] [blame] | 447 | #endif |
Satish kumar sugasi | da90009 | 2014-02-06 19:30:27 -0800 | [diff] [blame] | 448 | |
| 449 | |
| 450 | |
| 451 | /************************************************************************************ |
| 452 | ** Shutdown helper functions |
| 453 | ************************************************************************************/ |
| 454 | |
| 455 | static void bdt_shutdown(void) |
| 456 | { |
| 457 | bdt_log("shutdown bdroid test app\n"); |
| 458 | main_done = 1; |
| 459 | } |
| 460 | |
| 461 | |
| 462 | /***************************************************************************** |
| 463 | ** Android's init.rc does not yet support applying linux capabilities |
| 464 | *****************************************************************************/ |
| 465 | |
| 466 | static void config_permissions(void) |
| 467 | { |
| 468 | struct __user_cap_header_struct header; |
| 469 | struct __user_cap_data_struct cap; |
| 470 | |
| 471 | bdt_log("set_aid_and_cap : pid %d, uid %d gid %d", getpid(), getuid(), getgid()); |
| 472 | |
| 473 | header.pid = 0; |
| 474 | |
| 475 | prctl(PR_SET_KEEPCAPS, 1, 0, 0, 0); |
| 476 | |
| 477 | setuid(AID_BLUETOOTH); |
| 478 | setgid(AID_BLUETOOTH); |
| 479 | |
| 480 | header.version = _LINUX_CAPABILITY_VERSION; |
| 481 | |
| 482 | cap.effective = cap.permitted = cap.inheritable = |
| 483 | 1 << CAP_NET_RAW | |
| 484 | 1 << CAP_NET_ADMIN | |
| 485 | 1 << CAP_NET_BIND_SERVICE | |
| 486 | 1 << CAP_SYS_RAWIO | |
| 487 | 1 << CAP_SYS_NICE | |
| 488 | 1 << CAP_SETGID; |
| 489 | |
| 490 | capset(&header, &cap); |
| 491 | setgroups(sizeof(groups)/sizeof(groups[0]), groups); |
| 492 | } |
| 493 | |
| 494 | |
| 495 | |
| 496 | /***************************************************************************** |
| 497 | ** Logger API |
| 498 | *****************************************************************************/ |
| 499 | |
| 500 | void bdt_log(const char *fmt_str, ...) |
| 501 | { |
| 502 | static char buffer[1024]; |
| 503 | va_list ap; |
| 504 | |
| 505 | va_start(ap, fmt_str); |
| 506 | vsnprintf(buffer, 1024, fmt_str, ap); |
| 507 | va_end(ap); |
| 508 | |
| 509 | fprintf(stdout, "%s\n", buffer); |
| 510 | } |
| 511 | |
| 512 | /******************************************************************************* |
| 513 | ** Misc helper functions |
| 514 | *******************************************************************************/ |
| 515 | static const char* dump_bt_status(bt_status_t status) |
| 516 | { |
| 517 | switch(status) |
| 518 | { |
| 519 | CASE_RETURN_STR(BT_STATUS_SUCCESS) |
| 520 | CASE_RETURN_STR(BT_STATUS_FAIL) |
| 521 | CASE_RETURN_STR(BT_STATUS_NOT_READY) |
| 522 | CASE_RETURN_STR(BT_STATUS_NOMEM) |
| 523 | CASE_RETURN_STR(BT_STATUS_BUSY) |
| 524 | CASE_RETURN_STR(BT_STATUS_UNSUPPORTED) |
| 525 | |
| 526 | default: |
| 527 | return "unknown status code"; |
| 528 | } |
| 529 | } |
| 530 | |
| 531 | static void hex_dump(char *msg, void *data, int size, int trunc) |
| 532 | { |
| 533 | unsigned char *p = data; |
| 534 | unsigned char c; |
| 535 | int n; |
| 536 | char bytestr[4] = {0}; |
| 537 | char addrstr[10] = {0}; |
| 538 | char hexstr[ 16*3 + 5] = {0}; |
| 539 | char charstr[16*1 + 5] = {0}; |
| 540 | |
| 541 | bdt_log("%s \n", msg); |
| 542 | |
| 543 | /* truncate */ |
| 544 | if(trunc && (size>32)) |
| 545 | size = 32; |
| 546 | |
| 547 | for(n=1;n<=size;n++) { |
| 548 | if (n%16 == 1) { |
| 549 | /* store address for this line */ |
| 550 | snprintf(addrstr, sizeof(addrstr), "%.4x", |
| 551 | ((intptr_t)p-(intptr_t)data) ); |
| 552 | } |
| 553 | |
| 554 | c = *p; |
| 555 | if (isalnum(c) == 0) { |
| 556 | c = '.'; |
| 557 | } |
| 558 | |
| 559 | /* store hex str (for left side) */ |
| 560 | snprintf(bytestr, sizeof(bytestr), "%02X ", *p); |
| 561 | strncat(hexstr, bytestr, sizeof(hexstr)-strlen(hexstr)-1); |
| 562 | |
| 563 | /* store char str (for right side) */ |
| 564 | snprintf(bytestr, sizeof(bytestr), "%c", c); |
| 565 | strncat(charstr, bytestr, sizeof(charstr)-strlen(charstr)-1); |
| 566 | |
| 567 | if(n%16 == 0) { |
| 568 | /* line completed */ |
| 569 | bdt_log("[%4.4s] %-50.50s %s\n", addrstr, hexstr, charstr); |
| 570 | hexstr[0] = 0; |
| 571 | charstr[0] = 0; |
| 572 | } else if(n%8 == 0) { |
| 573 | /* half line: add whitespaces */ |
| 574 | strncat(hexstr, " ", sizeof(hexstr)-strlen(hexstr)-1); |
| 575 | strncat(charstr, " ", sizeof(charstr)-strlen(charstr)-1); |
| 576 | } |
| 577 | p++; /* next byte */ |
| 578 | } |
| 579 | |
| 580 | if (strlen(hexstr) > 0) { |
| 581 | /* print rest of buffer if not empty */ |
| 582 | bdt_log("[%4.4s] %-50.50s %s\n", addrstr, hexstr, charstr); |
| 583 | } |
| 584 | } |
| 585 | |
| 586 | /******************************************************************************* |
| 587 | ** Console helper functions |
| 588 | *******************************************************************************/ |
| 589 | |
| 590 | void skip_blanks(char **p) |
| 591 | { |
| 592 | while (**p == ' ') |
| 593 | (*p)++; |
| 594 | } |
| 595 | |
| 596 | uint32_t get_int(char **p, int DefaultValue) |
| 597 | { |
| 598 | uint32_t Value = 0; |
| 599 | unsigned char UseDefault; |
| 600 | |
| 601 | UseDefault = 1; |
| 602 | skip_blanks(p); |
| 603 | |
| 604 | while ( ((**p)<= '9' && (**p)>= '0') ) |
| 605 | { |
| 606 | Value = Value * 10 + (**p) - '0'; |
| 607 | UseDefault = 0; |
| 608 | (*p)++; |
| 609 | } |
| 610 | if (UseDefault) |
| 611 | return DefaultValue; |
| 612 | else |
| 613 | return Value; |
| 614 | } |
| 615 | |
| 616 | int get_signed_int(char **p, int DefaultValue) |
| 617 | { |
| 618 | int Value = 0; |
| 619 | unsigned char UseDefault; |
| 620 | unsigned char NegativeNum = 0; |
| 621 | |
| 622 | UseDefault = 1; |
| 623 | skip_blanks(p); |
| 624 | |
| 625 | if ((**p) == '-') |
| 626 | { |
| 627 | NegativeNum = 1; |
| 628 | (*p)++; |
| 629 | } |
| 630 | while ( ((**p)<= '9' && (**p)>= '0') ) |
| 631 | { |
| 632 | Value = Value * 10 + (**p) - '0'; |
| 633 | UseDefault = 0; |
| 634 | (*p)++; |
| 635 | } |
| 636 | |
| 637 | if (UseDefault) |
| 638 | return DefaultValue; |
| 639 | else |
| 640 | return ((NegativeNum == 0)? Value : -Value); |
| 641 | } |
| 642 | |
| 643 | void get_str(char **p, char *Buffer) |
| 644 | { |
| 645 | skip_blanks(p); |
| 646 | while (**p != 0 && **p != ' ') |
| 647 | { |
| 648 | *Buffer = **p; |
| 649 | (*p)++; |
| 650 | Buffer++; |
| 651 | } |
| 652 | |
| 653 | *Buffer = 0; |
| 654 | } |
| 655 | |
| 656 | uint32_t get_hex_any(char **p, int DefaultValue, unsigned int NumOfNibble) |
| 657 | { |
| 658 | uint32_t Value = 0; |
| 659 | unsigned char UseDefault; |
| 660 | |
| 661 | UseDefault = 1; |
| 662 | skip_blanks(p); |
| 663 | |
| 664 | while ((NumOfNibble) && (((**p)<= '9' && (**p)>= '0') || |
| 665 | ((**p)<= 'f' && (**p)>= 'a') || |
| 666 | ((**p)<= 'F' && (**p)>= 'A')) ) |
| 667 | { |
| 668 | if (**p >= 'a') |
| 669 | Value = Value * 16 + (**p) - 'a' + 10; |
| 670 | else if (**p >= 'A') |
| 671 | Value = Value * 16 + (**p) - 'A' + 10; |
| 672 | else |
| 673 | Value = Value * 16 + (**p) - '0'; |
| 674 | UseDefault = 0; |
| 675 | (*p)++; |
| 676 | NumOfNibble--; |
| 677 | } |
| 678 | |
| 679 | if (UseDefault) |
| 680 | return DefaultValue; |
| 681 | else |
| 682 | return Value; |
| 683 | } |
| 684 | uint32_t get_hex(char **p, int DefaultValue) |
| 685 | { |
| 686 | return (get_hex_any(p, DefaultValue, 8)); |
| 687 | } |
| 688 | uint32_t get_hex_byte(char **p, int DefaultValue) |
| 689 | { |
| 690 | return (get_hex_any(p, DefaultValue, 2)); |
| 691 | } |
| 692 | |
| 693 | void get_bdaddr(const char *str, bt_bdaddr_t *bd) { |
| 694 | char *d = ((char *)bd), *endp; |
| 695 | int i; |
| 696 | for(i = 0; i < 6; i++) { |
| 697 | *d++ = strtol(str, &endp, 16); |
| 698 | if (*endp != ':' && i != 5) { |
| 699 | memset(bd, 0, sizeof(bt_bdaddr_t)); |
| 700 | return; |
| 701 | } |
| 702 | str = endp + 1; |
| 703 | } |
| 704 | } |
| 705 | |
| 706 | #define is_cmd(str) ((strlen(str) == strlen(cmd)) && strncmp((const char *)&cmd, str, strlen(str)) == 0) |
| 707 | #define if_cmd(str) if (is_cmd(str)) |
| 708 | |
| 709 | typedef void (t_console_cmd_handler) (char *p); |
| 710 | |
| 711 | typedef struct { |
| 712 | const char *name; |
| 713 | t_console_cmd_handler *handler; |
| 714 | const char *help; |
| 715 | unsigned char is_job; |
| 716 | } t_cmd; |
| 717 | |
| 718 | |
| 719 | const t_cmd console_cmd_list[]; |
| 720 | static int console_cmd_maxlen = 0; |
| 721 | |
| 722 | static void cmdjob_handler(void *param) |
| 723 | { |
| 724 | char *job_cmd = (char*)param; |
| 725 | |
| 726 | bdt_log("cmdjob starting (%s)", job_cmd); |
| 727 | |
| 728 | process_cmd(job_cmd, 1); |
| 729 | |
| 730 | bdt_log("cmdjob terminating"); |
| 731 | |
| 732 | free(job_cmd); |
| 733 | } |
| 734 | |
| 735 | static int create_cmdjob(char *cmd) |
| 736 | { |
| 737 | pthread_t thread_id; |
| 738 | char *job_cmd; |
| 739 | |
| 740 | job_cmd = malloc(strlen(cmd)+1); /* freed in job handler */ |
Sai Aitharaju | d12d60e | 2015-02-06 09:20:32 +0530 | [diff] [blame] | 741 | if (job_cmd) |
| 742 | { |
| 743 | strlcpy(job_cmd, cmd,(strlen(cmd)+1)); |
| 744 | if (pthread_create(&thread_id, NULL, |
| 745 | (void*)cmdjob_handler, (void*)job_cmd)!=0) |
| 746 | perror("pthread_create"); |
| 747 | } |
| 748 | else |
| 749 | bdt_log("Gatt_test: Cannot Allocate memory for cmdjob"); |
Satish kumar sugasi | da90009 | 2014-02-06 19:30:27 -0800 | [diff] [blame] | 750 | |
| 751 | return 0; |
| 752 | } |
| 753 | |
| 754 | /******************************************************************************* |
| 755 | ** Load stack lib |
| 756 | *******************************************************************************/ |
| 757 | |
| 758 | int HAL_load(void) |
| 759 | { |
| 760 | int err = 0; |
| 761 | |
| 762 | hw_module_t* module; |
| 763 | hw_device_t* device; |
| 764 | |
| 765 | bdt_log("Loading HAL lib + extensions"); |
| 766 | |
| 767 | err = hw_get_module(BT_HARDWARE_MODULE_ID, (hw_module_t const**)&module); |
| 768 | if (err == 0) |
| 769 | { |
| 770 | |
| 771 | err = module->methods->open(module, BT_HARDWARE_MODULE_ID, &device); |
| 772 | bdt_log("HAL library open (%s)", strerror(err)); |
| 773 | if (err == 0) { |
| 774 | bt_device = (bluetooth_device_t *)device; |
| 775 | sBtInterface = bt_device->get_bluetooth_interface(); |
| 776 | } |
| 777 | } |
| 778 | |
Nitin Shivpure | 2906055 | 2014-09-10 11:28:06 +0530 | [diff] [blame] | 779 | bdt_log("HAL library loaded (%s) interface pointer =%x ", strerror(err), sBtInterface); |
Satish kumar sugasi | da90009 | 2014-02-06 19:30:27 -0800 | [diff] [blame] | 780 | |
| 781 | return err; |
| 782 | } |
| 783 | |
| 784 | int HAL_unload(void) |
| 785 | { |
| 786 | int err = 0; |
| 787 | |
| 788 | bdt_log("Unloading HAL lib"); |
| 789 | |
| 790 | sBtInterface = NULL; |
| 791 | |
| 792 | bdt_log("HAL library unloaded (%s)", strerror(err)); |
| 793 | |
| 794 | return err; |
| 795 | } |
| 796 | |
| 797 | /******************************************************************************* |
| 798 | ** HAL test functions & callbacks |
| 799 | *******************************************************************************/ |
| 800 | |
| 801 | void setup_test_env(void) |
| 802 | { |
| 803 | int i = 0; |
| 804 | |
| 805 | while (console_cmd_list[i].name != NULL) |
| 806 | { |
| 807 | console_cmd_maxlen = MAX(console_cmd_maxlen, (int)strlen(console_cmd_list[i].name)); |
| 808 | i++; |
| 809 | } |
| 810 | } |
| 811 | |
| 812 | void check_return_status(bt_status_t status) |
| 813 | { |
| 814 | if (status != BT_STATUS_SUCCESS) |
| 815 | { |
| 816 | bdt_log("HAL REQUEST FAILED status : %d (%s)", status, dump_bt_status(status)); |
| 817 | } |
| 818 | else |
| 819 | { |
| 820 | bdt_log("HAL REQUEST SUCCESS"); |
| 821 | } |
| 822 | } |
| 823 | /* |
| 824 | static void do_set_adv_params(char *p) |
| 825 | { |
| 826 | bt_bdaddr_t bd_addr = {{0}}; |
| 827 | int int_min = 0x0, int_max = 0x0, addr_type = 0; |
| 828 | int_max = get_int(&p, -1); |
| 829 | int_min = get_int(&p, -1); |
| 830 | if(int_max < int_min) |
| 831 | return; |
| 832 | // if(FALSE == GetBdAddr(p, &bd_addr)) return; |
| 833 | // sBtInterface->le_set_adv_params(int_min, int_max, &bd_addr, addr_type); |
| 834 | } |
Satish kumar sugasi | da90009 | 2014-02-06 19:30:27 -0800 | [diff] [blame] | 835 | */ |
| 836 | |
| 837 | static void do_set_localname(char *p) |
| 838 | { |
| 839 | printf("set name in progress: %s\n", p); |
| 840 | bt_property_t property = {BT_PROPERTY_BDNAME, strlen(p), p}; |
| 841 | status = sBtInterface->set_adapter_property(&property); |
| 842 | } |
| 843 | |
| 844 | static void adapter_state_changed(bt_state_t state) |
| 845 | { |
| 846 | int V1 = 1000, V2=2; |
| 847 | bt_property_t property = {9 /*BT_PROPERTY_DISCOVERY_TIMEOUT*/, 4, &V1}; |
| 848 | bt_property_t property1 = {7 /*SCAN*/, 2, &V2}; |
| 849 | bt_property_t property2 ={1,9,"GATTTOOL"}; |
| 850 | printf("ADAPTER STATE UPDATED : %s\n", (state == BT_STATE_OFF)?"OFF":"ON"); |
| 851 | |
| 852 | g_AdapterState = state; |
| 853 | |
| 854 | if (state == BT_STATE_ON) { |
| 855 | bt_enabled = 1; |
| 856 | status = sBtInterface->set_adapter_property(&property1); |
| 857 | status = sBtInterface->set_adapter_property(&property); |
| 858 | status = sBtInterface->set_adapter_property(&property2); |
| 859 | } else { |
| 860 | bt_enabled = 0; |
| 861 | } |
| 862 | } |
| 863 | |
| 864 | static void adapter_properties_changed(bt_status_t status, int num_properties, bt_property_t *properties) |
| 865 | { |
| 866 | char Bd_addr[15] = {0}; |
| 867 | if(NULL == properties) |
| 868 | { |
| 869 | printf("properties is null\n"); |
| 870 | return; |
| 871 | } |
| 872 | switch(properties->type) |
| 873 | { |
| 874 | case BT_PROPERTY_BDADDR: |
| 875 | memcpy(Bd_addr, properties->val, properties->len); |
| 876 | break; |
| 877 | // case BT_PROPERTY_ADAPTER_BLE_ADV_MODE: |
| 878 | // printf("Set in advertisement mode\n"); |
| 879 | // break; |
| 880 | default: |
| 881 | printf("property type not used\n"); |
| 882 | } |
| 883 | return; |
| 884 | } |
| 885 | |
| 886 | static void discovery_state_changed(bt_discovery_state_t state) |
| 887 | { |
| 888 | printf("Discovery State Updated : %s\n", (state == BT_DISCOVERY_STOPPED)?"STOPPED":"STARTED"); |
| 889 | } |
| 890 | |
| 891 | |
Nitin Shivpure | 2906055 | 2014-09-10 11:28:06 +0530 | [diff] [blame] | 892 | static void pin_request_cb(bt_bdaddr_t *remote_bd_addr, bt_bdname_t *bd_name, uint32_t cod, uint8_t secure ) |
Satish kumar sugasi | da90009 | 2014-02-06 19:30:27 -0800 | [diff] [blame] | 893 | { |
| 894 | int ret = 0; |
| 895 | remote_bd_address = remote_bd_addr; |
| 896 | //bt_pin_code_t pincode = {{0x31, 0x32, 0x33, 0x34}}; |
| 897 | printf("Enter the pin key displayed in the remote device and terminate the key entry with .\n"); |
| 898 | |
| 899 | /*if(BT_STATUS_SUCCESS != sBtInterface->pin_reply(remote_bd_addr, TRUE, 4, &pincode)) |
| 900 | { |
| 901 | printf("Pin Reply failed\n"); |
| 902 | }*/ |
| 903 | } |
| 904 | static void ssp_request_cb(bt_bdaddr_t *remote_bd_addr, bt_bdname_t *bd_name, |
| 905 | uint32_t cod, bt_ssp_variant_t pairing_variant, uint32_t pass_key) |
| 906 | { |
| 907 | printf("ssp_request_cb : name=%s variant=%d passkey=%u\n", bd_name->name, pairing_variant, pass_key); |
| 908 | if(BT_STATUS_SUCCESS != sBtInterface->ssp_reply(remote_bd_addr, pairing_variant, TRUE, pass_key)) |
| 909 | { |
| 910 | printf("SSP Reply failed\n"); |
| 911 | } |
| 912 | } |
| 913 | |
| 914 | static void bond_state_changed_cb(bt_status_t status, bt_bdaddr_t *remote_bd_addr, bt_bond_state_t state) |
| 915 | { |
| 916 | g_PairState = state; |
| 917 | } |
| 918 | |
| 919 | static void acl_state_changed(bt_status_t status, bt_bdaddr_t *remote_bd_addr, bt_acl_state_t state) |
| 920 | { |
| 921 | printf("acl_state_changed : remote_bd_addr=%02x:%02x:%02x:%02x:%02x:%02x, acl status=%s \n", |
| 922 | remote_bd_addr->address[0], remote_bd_addr->address[1], remote_bd_addr->address[2], |
| 923 | remote_bd_addr->address[3], remote_bd_addr->address[4], remote_bd_addr->address[5], |
| 924 | (state == BT_ACL_STATE_CONNECTED)?"ACL Connected" :"ACL Disconnected" |
| 925 | ); |
| 926 | } |
| 927 | static void dut_mode_recv(uint16_t opcode, uint8_t *buf, uint8_t len) |
| 928 | { |
| 929 | bdt_log("DUT MODE RECV : NOT IMPLEMENTED"); |
| 930 | } |
| 931 | |
| 932 | static void le_test_mode(bt_status_t status, uint16_t packet_count) |
| 933 | { |
| 934 | bdt_log("LE TEST MODE END status:%s number_of_packets:%d", dump_bt_status(status), packet_count); |
| 935 | } |
| 936 | |
| 937 | static bool set_wake_alarm(uint64_t delay_millis, bool should_wake, alarm_cb cb, void *data) |
| 938 | { |
Satish kumar sugasi | 6ee1994 | 2014-10-20 18:22:28 -0700 | [diff] [blame] | 939 | return TRUE; |
Satish kumar sugasi | da90009 | 2014-02-06 19:30:27 -0800 | [diff] [blame] | 940 | } |
| 941 | |
| 942 | static int acquire_wake_lock(const char *lock_name) |
| 943 | { |
Satish kumar sugasi | 6ee1994 | 2014-10-20 18:22:28 -0700 | [diff] [blame] | 944 | return BT_STATUS_SUCCESS; |
Satish kumar sugasi | da90009 | 2014-02-06 19:30:27 -0800 | [diff] [blame] | 945 | } |
Satish kumar sugasi | 6ee1994 | 2014-10-20 18:22:28 -0700 | [diff] [blame] | 946 | |
Satish kumar sugasi | da90009 | 2014-02-06 19:30:27 -0800 | [diff] [blame] | 947 | static int release_wake_lock(const char *lock_name) |
| 948 | { |
Satish kumar sugasi | 6ee1994 | 2014-10-20 18:22:28 -0700 | [diff] [blame] | 949 | return BT_STATUS_SUCCESS; |
Satish kumar sugasi | da90009 | 2014-02-06 19:30:27 -0800 | [diff] [blame] | 950 | } |
| 951 | |
| 952 | static bt_callbacks_t bt_callbacks = { |
| 953 | sizeof(bt_callbacks_t), |
| 954 | adapter_state_changed, |
| 955 | adapter_properties_changed, /*adapter_properties_cb */ |
| 956 | NULL, /* remote_device_properties_cb */ |
| 957 | NULL, /* device_found_cb */ |
| 958 | discovery_state_changed, /* discovery_state_changed_cb */ |
| 959 | pin_request_cb, /* pin_request_cb */ |
| 960 | ssp_request_cb, /* ssp_request_cb */ |
| 961 | bond_state_changed_cb, /*bond_state_changed_cb */ |
| 962 | acl_state_changed, /* acl_state_changed_cb */ |
| 963 | NULL, /* thread_evt_cb */ |
| 964 | dut_mode_recv, /*dut_mode_recv_cb */ |
Nitin Shivpure | 2906055 | 2014-09-10 11:28:06 +0530 | [diff] [blame] | 965 | le_test_mode, /* le_test_mode_cb */ |
| 966 | NULL, |
| 967 | NULL, |
| 968 | NULL, |
| 969 | NULL, |
| 970 | NULL |
Satish kumar sugasi | da90009 | 2014-02-06 19:30:27 -0800 | [diff] [blame] | 971 | }; |
| 972 | |
| 973 | static bt_os_callouts_t bt_os_callbacks = { |
| 974 | sizeof(bt_os_callouts_t), |
Satish kumar sugasi | 6ee1994 | 2014-10-20 18:22:28 -0700 | [diff] [blame] | 975 | set_wake_alarm, |
| 976 | acquire_wake_lock, |
| 977 | release_wake_lock |
Nitin Shivpure | 2906055 | 2014-09-10 11:28:06 +0530 | [diff] [blame] | 978 | }; |
Satish kumar sugasi | da90009 | 2014-02-06 19:30:27 -0800 | [diff] [blame] | 979 | |
Satish kumar sugasi | da90009 | 2014-02-06 19:30:27 -0800 | [diff] [blame] | 980 | static void l2test_l2c_connect_ind_cb(BD_ADDR bd_addr, UINT16 lcid, UINT16 psm, UINT8 id) |
| 981 | { |
| 982 | |
| 983 | if((L2CAP_FCR_ERTM_MODE == g_Fcr_Mode) || (L2CAP_FCR_STREAM_MODE == g_Fcr_Mode)) { |
| 984 | sL2capInterface->ErtmConnectRsp(bd_addr, id, lcid, L2CAP_CONN_OK, L2CAP_CONN_OK, &t_ertm_info); |
| 985 | } else { |
| 986 | sL2capInterface->ConnectRsp(bd_addr, id, lcid, L2CAP_CONN_OK, L2CAP_CONN_OK); |
| 987 | } |
| 988 | { |
| 989 | tL2CAP_CFG_INFO cfg = tl2cap_cfg_info; |
| 990 | if ((!sL2capInterface->ConfigReq (lcid, &cfg)) && cfg.fcr_present |
| 991 | && cfg.fcr.mode != L2CAP_FCR_BASIC_MODE) { |
| 992 | cfg.fcr.mode = L2CAP_FCR_BASIC_MODE; |
| 993 | cfg.fcr_present = FALSE; |
| 994 | sL2capInterface->ConfigReq (lcid, &cfg); |
| 995 | } |
| 996 | } |
| 997 | g_ConnectionState = CONNECT; |
| 998 | g_lcid = lcid; |
| 999 | } |
| 1000 | |
| 1001 | static void l2test_l2c_connect_cfm_cb(UINT16 lcid, UINT16 result) |
| 1002 | { |
| 1003 | |
| 1004 | if ((result == L2CAP_CONN_OK) ) { |
| 1005 | L2cap_conn_state = L2CAP_CONN_SETUP; |
| 1006 | tL2CAP_CFG_INFO cfg = tl2cap_cfg_info; |
| 1007 | sL2capInterface->ConfigReq (lcid, &cfg); |
| 1008 | g_imtu = cfg.mtu; |
| 1009 | g_ConnectionState = CONNECT; |
| 1010 | g_lcid = lcid; |
| 1011 | } |
| 1012 | } |
| 1013 | |
| 1014 | static void l2test_l2c_connect_pnd_cb(UINT16 lcid) |
| 1015 | { |
| 1016 | g_ConnectionState = CONNECTING; |
| 1017 | } |
| 1018 | static void l2test_l2c_config_ind_cb(UINT16 lcid, tL2CAP_CFG_INFO *p_cfg) |
| 1019 | { |
| 1020 | p_cfg->result = L2CAP_CFG_OK; |
| 1021 | p_cfg->fcr_present = FALSE; |
| 1022 | if(p_cfg->mtu_present) g_omtu = p_cfg->mtu; |
| 1023 | else g_omtu = L2CAP_DEFAULT_MTU; |
| 1024 | sL2capInterface->ConfigRsp (lcid, p_cfg); |
| 1025 | return; |
| 1026 | } |
| 1027 | |
| 1028 | static void l2test_l2c_config_cfm_cb(UINT16 lcid, tL2CAP_CFG_INFO *p_cfg) |
| 1029 | { |
| 1030 | |
| 1031 | /* For now, always accept configuration from the other side */ |
| 1032 | if (p_cfg->result == L2CAP_CFG_OK) { |
| 1033 | printf("\nl2test_l2c_config_cfm_cb Success\n"); |
| 1034 | } else { |
| 1035 | |
| 1036 | /* If peer has rejected FCR and suggested basic then try basic */ |
| 1037 | if (p_cfg->fcr_present) { |
| 1038 | tL2CAP_CFG_INFO cfg = tl2cap_cfg_info; |
| 1039 | cfg.fcr_present = FALSE; |
| 1040 | sL2capInterface->ConfigReq (lcid, &cfg); |
| 1041 | // Remain in configure state |
| 1042 | return; |
| 1043 | } |
| 1044 | sL2capInterface->DisconnectReq(lcid); |
| 1045 | } |
| 1046 | if(0 == g_omtu) g_omtu = L2CAP_DEFAULT_MTU; |
| 1047 | } |
| 1048 | |
| 1049 | static void l2test_l2c_disconnect_ind_cb(UINT16 lcid, BOOLEAN ack_needed) |
| 1050 | { |
| 1051 | if (ack_needed) |
| 1052 | { |
| 1053 | /* send L2CAP disconnect response */ |
| 1054 | sL2capInterface->DisconnectRsp(lcid); |
| 1055 | } |
| 1056 | g_ConnectionState = DISCONNECTING; |
| 1057 | g_lcid = 0; |
| 1058 | } |
| 1059 | static void l2test_l2c_disconnect_cfm_cb(UINT16 lcid, UINT16 result) |
| 1060 | { |
| 1061 | g_ConnectionState = DISCONNECT; |
| 1062 | g_lcid = 0; |
| 1063 | } |
| 1064 | static void l2test_l2c_QoSViolationInd(BD_ADDR bd_addr) |
| 1065 | { |
| 1066 | printf("l2test_l2c_QoSViolationInd\n"); |
| 1067 | } |
| 1068 | static void l2test_l2c_data_ind_cb(UINT16 lcid, BT_HDR *p_buf) |
| 1069 | { |
| 1070 | printf("l2test_l2c_data_ind_cb:: event=%u, len=%u, offset=%u, layer_specific=%u\n", p_buf->event, p_buf->len, p_buf->offset, p_buf->layer_specific); |
| 1071 | } |
| 1072 | static void l2test_l2c_congestion_ind_cb(UINT16 lcid, BOOLEAN is_congested) |
| 1073 | { |
| 1074 | printf("l2test_l2c_congestion_ind_cb\n"); |
| 1075 | } |
| 1076 | |
| 1077 | static void l2test_l2c_tx_complete_cb (UINT16 lcid, UINT16 NoOfSDU) |
| 1078 | { |
| 1079 | printf("l2test_l2c_tx_complete_cb, cid=0x%x, SDUs=%u\n", lcid, NoOfSDU); |
| 1080 | } |
| 1081 | |
| 1082 | static void l2c_echo_rsp_cb(UINT16 p) |
| 1083 | { |
| 1084 | printf("Ping Response = %s\n", (L2CAP_PING_RESULT_OK==p) ?"Ping Reply OK" :(L2CAP_PING_RESULT_NO_LINK==p) ?"Link Could Not be setup" :"Remote L2cap did not reply"); |
| 1085 | } |
| 1086 | |
| 1087 | |
| 1088 | /* L2CAP callback function structure */ |
| 1089 | static tL2CAP_APPL_INFO l2test_l2c_appl = { |
| 1090 | // sizeof(l2test_l2c_appl), |
| 1091 | l2test_l2c_connect_ind_cb, |
| 1092 | l2test_l2c_connect_cfm_cb, |
| 1093 | l2test_l2c_connect_pnd_cb, |
| 1094 | l2test_l2c_config_ind_cb, |
| 1095 | l2test_l2c_config_cfm_cb, |
| 1096 | l2test_l2c_disconnect_ind_cb, |
| 1097 | l2test_l2c_disconnect_cfm_cb, |
| 1098 | l2test_l2c_QoSViolationInd, |
| 1099 | l2test_l2c_data_ind_cb, |
| 1100 | l2test_l2c_congestion_ind_cb, |
| 1101 | l2test_l2c_tx_complete_cb |
| 1102 | }; |
| 1103 | |
| 1104 | |
| 1105 | |
| 1106 | |
| 1107 | void bdt_init(void) |
| 1108 | { |
| 1109 | bdt_log("INIT BT "); |
| 1110 | status = sBtInterface->init(&bt_callbacks); |
| 1111 | status = sBtInterface->set_os_callouts(&bt_os_callbacks); |
| 1112 | check_return_status(status); |
| 1113 | } |
| 1114 | |
| 1115 | void bdt_enable(void) |
| 1116 | { |
| 1117 | bdt_log("ENABLE BT"); |
| 1118 | if (bt_enabled) { |
| 1119 | bdt_log("Bluetooth is already enabled"); |
| 1120 | return; |
| 1121 | } |
Dirk Vogt | 9487a25 | 2016-06-21 09:55:17 +0200 | [diff] [blame] | 1122 | status = sBtInterface->enable(false); |
Satish kumar sugasi | da90009 | 2014-02-06 19:30:27 -0800 | [diff] [blame] | 1123 | |
| 1124 | check_return_status(status); |
| 1125 | } |
| 1126 | |
| 1127 | void bdt_disable(void) |
| 1128 | { |
| 1129 | bdt_log("DISABLE BT"); |
| 1130 | if (!bt_enabled) { |
| 1131 | bdt_log("Bluetooth is already disabled"); |
| 1132 | return; |
| 1133 | } |
| 1134 | status = sBtInterface->disable(); |
| 1135 | |
| 1136 | check_return_status(status); |
| 1137 | } |
| 1138 | |
| 1139 | void do_pairing(char *p) |
| 1140 | { |
| 1141 | bt_bdaddr_t bd_addr = {{0}}; |
Nitin Shivpure | 2906055 | 2014-09-10 11:28:06 +0530 | [diff] [blame] | 1142 | int transport = GATT_TRANSPORT_LE; |
Satish kumar sugasi | da90009 | 2014-02-06 19:30:27 -0800 | [diff] [blame] | 1143 | if(FALSE == GetBdAddr(p, &bd_addr)) return; // arg1 |
Nitin Shivpure | 2906055 | 2014-09-10 11:28:06 +0530 | [diff] [blame] | 1144 | if(BT_STATUS_SUCCESS != sBtInterface->create_bond(&bd_addr, transport)) |
Satish kumar sugasi | da90009 | 2014-02-06 19:30:27 -0800 | [diff] [blame] | 1145 | { |
| 1146 | printf("Failed to Initiate Pairing \n"); |
| 1147 | return; |
| 1148 | } |
| 1149 | } |
| 1150 | |
| 1151 | void bdt_dut_mode_configure(char *p) |
| 1152 | { |
| 1153 | int32_t mode = -1; |
| 1154 | |
| 1155 | bdt_log("BT DUT MODE CONFIGURE"); |
| 1156 | if (!bt_enabled) { |
| 1157 | bdt_log("Bluetooth must be enabled for test_mode to work."); |
| 1158 | return; |
| 1159 | } |
| 1160 | mode = get_signed_int(&p, mode); |
| 1161 | if ((mode != 0) && (mode != 1)) { |
| 1162 | bdt_log("Please specify mode: 1 to enter, 0 to exit"); |
| 1163 | return; |
| 1164 | } |
| 1165 | status = sBtInterface->dut_mode_configure(mode); |
| 1166 | |
| 1167 | check_return_status(status); |
| 1168 | } |
| 1169 | |
| 1170 | #define HCI_LE_RECEIVER_TEST_OPCODE 0x201D |
| 1171 | #define HCI_LE_TRANSMITTER_TEST_OPCODE 0x201E |
| 1172 | #define HCI_LE_END_TEST_OPCODE 0x201F |
| 1173 | |
| 1174 | void bdt_le_test_mode(char *p) |
| 1175 | { |
| 1176 | int cmd; |
| 1177 | unsigned char buf[3]; |
| 1178 | int arg1, arg2, arg3; |
| 1179 | |
| 1180 | bdt_log("BT LE TEST MODE"); |
| 1181 | if (!bt_enabled) { |
| 1182 | bdt_log("Bluetooth must be enabled for le_test to work."); |
| 1183 | return; |
| 1184 | } |
| 1185 | |
| 1186 | memset(buf, 0, sizeof(buf)); |
| 1187 | cmd = get_int(&p, 0); |
| 1188 | switch (cmd) |
| 1189 | { |
| 1190 | case 0x1: /* RX TEST */ |
| 1191 | arg1 = get_int(&p, -1); |
| 1192 | if (arg1 < 0) bdt_log("%s Invalid arguments", __FUNCTION__); |
| 1193 | buf[0] = arg1; |
| 1194 | status = sBtInterface->le_test_mode(HCI_LE_RECEIVER_TEST_OPCODE, buf, 1); |
| 1195 | break; |
| 1196 | case 0x2: /* TX TEST */ |
| 1197 | arg1 = get_int(&p, -1); |
| 1198 | arg2 = get_int(&p, -1); |
| 1199 | arg3 = get_int(&p, -1); |
| 1200 | if ((arg1 < 0) || (arg2 < 0) || (arg3 < 0)) |
| 1201 | bdt_log("%s Invalid arguments", __FUNCTION__); |
| 1202 | buf[0] = arg1; |
| 1203 | buf[1] = arg2; |
| 1204 | buf[2] = arg3; |
| 1205 | status = sBtInterface->le_test_mode(HCI_LE_TRANSMITTER_TEST_OPCODE, buf, 3); |
| 1206 | break; |
| 1207 | case 0x3: /* END TEST */ |
| 1208 | status = sBtInterface->le_test_mode(HCI_LE_END_TEST_OPCODE, buf, 0); |
| 1209 | break; |
| 1210 | default: |
| 1211 | bdt_log("Unsupported command"); |
| 1212 | return; |
| 1213 | break; |
| 1214 | } |
| 1215 | if (status != BT_STATUS_SUCCESS) |
| 1216 | { |
| 1217 | bdt_log("%s Test 0x%x Failed with status:0x%x", __FUNCTION__, cmd, status); |
| 1218 | } |
| 1219 | return; |
| 1220 | } |
| 1221 | |
| 1222 | void bdt_cleanup(void) |
| 1223 | { |
| 1224 | bdt_log("CLEANUP"); |
| 1225 | sBtInterface->cleanup(); |
| 1226 | } |
| 1227 | |
| 1228 | /******************************************************************************* |
| 1229 | ** Console commands |
| 1230 | *******************************************************************************/ |
| 1231 | |
| 1232 | void do_help(char *p) |
| 1233 | { |
| 1234 | int i = 0; |
| 1235 | int max = 0; |
| 1236 | char line[128]; |
| 1237 | int pos = 0; |
| 1238 | |
| 1239 | while (console_cmd_list[i].name != NULL) |
| 1240 | { |
| 1241 | pos = snprintf(line, 128,"%s", (char*)console_cmd_list[i].name); |
| 1242 | bdt_log("%s %s\n", (char*)line, (char*)console_cmd_list[i].help); |
| 1243 | i++; |
| 1244 | } |
| 1245 | } |
| 1246 | |
| 1247 | void do_quit(char *p) |
| 1248 | { |
| 1249 | bdt_shutdown(); |
| 1250 | } |
| 1251 | |
| 1252 | /******************************************************************* |
| 1253 | * |
| 1254 | * BT TEST CONSOLE COMMANDS |
| 1255 | * |
| 1256 | * Parses argument lists and passes to API test function |
| 1257 | * |
| 1258 | */ |
| 1259 | |
| 1260 | void do_init(char *p) |
| 1261 | { |
| 1262 | bdt_init(); |
| 1263 | } |
| 1264 | |
| 1265 | void do_enable(char *p) |
| 1266 | { |
| 1267 | bdt_enable(); |
| 1268 | } |
| 1269 | |
| 1270 | void do_disable(char *p) |
| 1271 | { |
| 1272 | bdt_disable(); |
| 1273 | } |
| 1274 | void do_dut_mode_configure(char *p) |
| 1275 | { |
| 1276 | bdt_dut_mode_configure(p); |
| 1277 | } |
| 1278 | |
| 1279 | void do_le_test_mode(char *p) |
| 1280 | { |
| 1281 | bdt_le_test_mode(p); |
| 1282 | } |
| 1283 | |
| 1284 | void do_cleanup(char *p) |
| 1285 | { |
| 1286 | bdt_cleanup(); |
| 1287 | } |
| 1288 | |
| 1289 | |
| 1290 | void do_le_client_register(char *p) |
| 1291 | { |
| 1292 | bt_status_t Ret; |
| 1293 | int Idx; |
| 1294 | tBT_UUID uuid; |
| 1295 | bt_uuid_t bt_uuid; |
| 1296 | |
| 1297 | skip_blanks(&p); |
| 1298 | Idx = atoi(p); |
| 1299 | |
| 1300 | switch(Idx) |
| 1301 | { |
| 1302 | case 1: |
| 1303 | uuid.len = LEN_UUID_128; |
| 1304 | memcpy(&uuid.uu.uuid128, "\x00\x00\xA0\x0C\x00\x00\x00\x00\x01\x23\x45\x67\x89\xAB\xCD\xEF", 16); //0000A00C-0000-0000-0123-456789ABCDEF |
| 1305 | memcpy(&bt_uuid.uu, "\x00\x00\xA0\x0C\x00\x00\x00\x00\x01\x23\x45\x67\x89\xAB\xCD\xEF", 16); //0000A00C-0000-0000-0123-456789ABCDEF |
| 1306 | break; |
| 1307 | case 2: |
| 1308 | uuid.len = LEN_UUID_128; |
| 1309 | memcpy(&uuid.uu.uuid128, "\x11\x22\xA0\x0C\x00\x00\x00\x00\x01\x23\x45\x67\x89\xAB\xCD\xEF", 16); //1122A00C-0000-0000-0123-456789ABCDEF |
| 1310 | memcpy(&bt_uuid.uu, "\x11\x22\xA0\x0C\x00\x00\x00\x00\x01\x23\x45\x67\x89\xAB\xCD\xEF", 16); //1122A00C-0000-0000-0123-456789ABCDEF |
| 1311 | break; |
| 1312 | default: |
| 1313 | printf("%s:: ERROR: no matching uuid \n", __FUNCTION__); |
| 1314 | return; |
| 1315 | } |
| 1316 | if(Btif_gatt_layer) |
| 1317 | { |
| 1318 | Ret = sGattIfaceScan->client->register_client(&bt_uuid); |
| 1319 | } |
| 1320 | else |
| 1321 | { |
| 1322 | g_client_if = sGattInterface->Register(&uuid, &sGattCB); |
| 1323 | sleep(2); |
| 1324 | sGattInterface->StartIf(g_client_if); |
| 1325 | } |
| 1326 | } |
| 1327 | |
| 1328 | void do_le_client_deregister(char *p) |
| 1329 | { |
| 1330 | bt_status_t Ret; |
| 1331 | |
| 1332 | if(Btif_gatt_layer) |
| 1333 | { |
| 1334 | if(0 == g_client_if_scan) |
| 1335 | { |
| 1336 | printf("%s:: ERROR: no application registered\n", __FUNCTION__); |
| 1337 | return; |
| 1338 | } |
| 1339 | Ret = sGattIfaceScan->client->unregister_client(g_client_if_scan); |
| 1340 | printf("%s:: Ret=%d\n", __FUNCTION__, Ret); |
| 1341 | } |
| 1342 | else |
| 1343 | { |
| 1344 | if(0 == g_client_if) |
| 1345 | { |
| 1346 | printf("%s:: ERROR: no application registered\n", __FUNCTION__); |
| 1347 | return; |
| 1348 | } |
| 1349 | sGattInterface->Deregister(g_client_if); |
| 1350 | } |
| 1351 | } |
| 1352 | |
| 1353 | void do_le_client_connect (char *p) |
| 1354 | { |
Nitin Shivpure | 2906055 | 2014-09-10 11:28:06 +0530 | [diff] [blame] | 1355 | BOOLEAN Ret = false; |
| 1356 | bt_bdaddr_t bd_addr = {{0}}; |
Satish kumar sugasi | 544a26e | 2014-09-05 12:36:54 -0700 | [diff] [blame] | 1357 | int transport = BT_TRANSPORT_BR_EDR; |
Satish kumar sugasi | da90009 | 2014-02-06 19:30:27 -0800 | [diff] [blame] | 1358 | transport = get_int(&p, -1); |
| 1359 | if(FALSE == GetBdAddr(p, &bd_addr)) return; |
Satish kumar sugasi | 544a26e | 2014-09-05 12:36:54 -0700 | [diff] [blame] | 1360 | |
| 1361 | if(transport == BT_TRANSPORT_BR_EDR) |
| 1362 | { |
| 1363 | //Outgoing Connection |
| 1364 | |
| 1365 | // g_SecLevel |= BTM_SEC_OUT_AUTHENTICATE; |
| 1366 | // g_SecLevel |= BTM_SEC_OUT_ENCRYPT ; |
Nitin Shivpure | 2906055 | 2014-09-10 11:28:06 +0530 | [diff] [blame] | 1367 | g_PSM= 1; |
Satish kumar sugasi | 6ee1994 | 2014-10-20 18:22:28 -0700 | [diff] [blame] | 1368 | g_SecLevel = 0; |
Satish kumar sugasi | da90009 | 2014-02-06 19:30:27 -0800 | [diff] [blame] | 1369 | printf("g_SecLevel = %d \n", g_SecLevel); |
| 1370 | sL2capInterface->RegisterPsm(g_PSM, g_ConnType, g_SecLevel /*BTM_SEC_IN_AUTHORIZE */); |
| 1371 | sleep(3); |
| 1372 | |
Satish kumar sugasi | 6ee1994 | 2014-10-20 18:22:28 -0700 | [diff] [blame] | 1373 | l2c_connect(&bd_addr); |
Satish kumar sugasi | 544a26e | 2014-09-05 12:36:54 -0700 | [diff] [blame] | 1374 | } |
| 1375 | else if(Btif_gatt_layer) |
Satish kumar sugasi | da90009 | 2014-02-06 19:30:27 -0800 | [diff] [blame] | 1376 | { |
| 1377 | Ret = sGattIfaceScan->client->connect(g_client_if_scan, &bd_addr, TRUE, transport); |
| 1378 | } |
| 1379 | else |
| 1380 | { |
| 1381 | Ret = sGattInterface->Connect(g_client_if, bd_addr.address, TRUE, transport); |
| 1382 | } |
| 1383 | printf("%s:: Ret=%d \n", __FUNCTION__, Ret); |
| 1384 | } |
| 1385 | |
Satish kumar sugasi | 87a7690 | 2014-10-03 17:07:00 -0700 | [diff] [blame] | 1386 | void do_le_client_refresh (char *p) |
| 1387 | { |
| 1388 | BOOLEAN Ret; |
| 1389 | bt_bdaddr_t bd_addr = {{0}}; |
| 1390 | if(FALSE == GetBdAddr(p, &bd_addr)) return; |
| 1391 | |
| 1392 | if(Btif_gatt_layer) |
| 1393 | { |
| 1394 | Ret = sGattIfaceScan->client->refresh(g_client_if_scan, &bd_addr); |
| 1395 | printf("%s:: Ret=%d \n", __FUNCTION__, Ret); |
| 1396 | } |
| 1397 | } |
| 1398 | |
Satish kumar sugasi | c470d8c | 2014-10-20 14:09:05 -0700 | [diff] [blame] | 1399 | void do_le_conn_param_update(char *p) |
| 1400 | { |
| 1401 | BOOLEAN Ret; |
| 1402 | bt_bdaddr_t bd_addr = {{0}}; |
| 1403 | int min_interval = 24; |
| 1404 | int max_interval = 40; |
| 1405 | int latency = 0; |
| 1406 | int timeout = 2000; |
| 1407 | min_interval = get_int(&p, -1); |
| 1408 | max_interval = get_int(&p, -1); |
| 1409 | latency = get_int(&p, -1); |
| 1410 | if(!min_interval) |
| 1411 | min_interval = 24; |
| 1412 | if(!max_interval) |
| 1413 | max_interval = 40; |
| 1414 | if(FALSE == GetBdAddr(p, &bd_addr)) return; |
| 1415 | Ret = sGattIfaceScan->client->conn_parameter_update(&bd_addr,min_interval,max_interval,latency,timeout); |
| 1416 | printf("%s:: Ret=%d \n", __FUNCTION__, Ret); |
| 1417 | |
| 1418 | } |
Satish kumar sugasi | 87a7690 | 2014-10-03 17:07:00 -0700 | [diff] [blame] | 1419 | |
Satish kumar sugasi | da90009 | 2014-02-06 19:30:27 -0800 | [diff] [blame] | 1420 | void do_le_client_connect_auto (char *p) |
| 1421 | { |
| 1422 | BOOLEAN Ret; |
| 1423 | bt_bdaddr_t bd_addr = {{0}}; |
| 1424 | if(FALSE == GetBdAddr(p, &bd_addr)) return; |
| 1425 | |
| 1426 | if(Btif_gatt_layer) |
| 1427 | { |
| 1428 | Ret = sGattIfaceScan->client->connect(g_client_if_scan, &bd_addr, FALSE,BT_TRANSPORT_LE); |
| 1429 | } |
| 1430 | else |
| 1431 | { |
| 1432 | Ret = sGattInterface->Connect(g_client_if, bd_addr.address, FALSE,BT_TRANSPORT_LE); |
| 1433 | } |
| 1434 | } |
| 1435 | |
| 1436 | |
| 1437 | void do_le_client_disconnect (char *p) |
| 1438 | { |
| 1439 | bt_status_t Ret; |
| 1440 | bt_bdaddr_t bd_addr = {{0}}; |
| 1441 | if(FALSE == GetBdAddr(p, &bd_addr)) return; |
| 1442 | |
| 1443 | if(Btif_gatt_layer) |
| 1444 | { |
| 1445 | Ret = sGattIfaceScan->client->disconnect(g_client_if_scan, &bd_addr, g_conn_id); |
| 1446 | } |
| 1447 | else |
| 1448 | { |
| 1449 | Ret = sGattInterface->Disconnect(g_conn_id); |
| 1450 | } |
| 1451 | } |
| 1452 | |
| 1453 | void do_le_client_scan_start (char *p) |
| 1454 | { |
| 1455 | bt_status_t Ret; |
| 1456 | Ret = sGattIfaceScan->client->scan(TRUE); |
| 1457 | } |
| 1458 | |
| 1459 | void do_le_client_scan_stop (char *p) |
| 1460 | { |
| 1461 | bt_status_t Ret; |
| 1462 | Ret = sGattIfaceScan->client->scan(FALSE); |
| 1463 | } |
| 1464 | |
| 1465 | void do_le_client_set_adv_data(char *p) |
| 1466 | { |
| 1467 | bt_status_t Ret; |
| 1468 | bool SetScanRsp = FALSE; |
| 1469 | bool IncludeName = FALSE; |
| 1470 | bool IncludeTxPower = FALSE; |
| 1471 | int min_conn_interval = 100; |
| 1472 | int max_conn_interval = 1000; |
| 1473 | |
| 1474 | SetScanRsp = get_int(&p, -1); // arg1 Other than zero will be considered as true. |
| 1475 | IncludeName = get_int(&p, -1); // arg2 Other than zero will be considered as true. |
| 1476 | IncludeTxPower = get_int(&p, -1); // arg3 Other than zero will be considered as true. |
| 1477 | min_conn_interval = get_int(&p, -1); // arg3 Other than zero will be considered as true. |
| 1478 | max_conn_interval = get_int(&p, -1); // arg3 Other than zero will be considered as true. |
| 1479 | |
| 1480 | //To start with we are going with hard-code values. |
| 1481 | Ret = sGattIfaceScan->client->set_adv_data(/*g_server_if*/ g_server_if_scan /*g_client_if_scan*/, SetScanRsp, IncludeName, IncludeTxPower, min_conn_interval, max_conn_interval, 0,8, "QUALCOMM", 0, NULL,0,NULL); |
| 1482 | } |
| 1483 | |
| 1484 | void do_le_client_multi_adv_set_inst_data(char *p) |
| 1485 | { |
| 1486 | bt_status_t Ret; |
| 1487 | bool SetScanRsp = FALSE; |
Satish kumar sugasi | 87a7690 | 2014-10-03 17:07:00 -0700 | [diff] [blame] | 1488 | bool IncludeName = TRUE; |
| 1489 | bool IncludeTxPower = TRUE; |
Satish kumar sugasi | 544a26e | 2014-09-05 12:36:54 -0700 | [diff] [blame] | 1490 | |
Satish kumar sugasi | da90009 | 2014-02-06 19:30:27 -0800 | [diff] [blame] | 1491 | SetScanRsp = get_int(&p, -1); // arg1 Other than zero will be considered as true. |
| 1492 | IncludeName = get_int(&p, -1); // arg2 Other than zero will be considered as true. |
| 1493 | IncludeTxPower = get_int(&p, -1); // arg3 Other than zero will be considered as true. |
Satish kumar sugasi | 544a26e | 2014-09-05 12:36:54 -0700 | [diff] [blame] | 1494 | |
Satish kumar sugasi | da90009 | 2014-02-06 19:30:27 -0800 | [diff] [blame] | 1495 | //To start with we are going with hard-code values. |
| 1496 | Ret = sGattIfaceScan->client->multi_adv_set_inst_data(g_client_if_scan /*g_client_if_scan*/, SetScanRsp, IncludeName, IncludeTxPower,0,8, "QUALCOMM", 0, NULL,0,NULL); |
| 1497 | } |
| 1498 | |
| 1499 | void do_le_client_adv_update(char *p) |
| 1500 | { |
| 1501 | bt_status_t Ret; |
| 1502 | int TxPower = 3; |
Satish kumar sugasi | 6ee1994 | 2014-10-20 18:22:28 -0700 | [diff] [blame] | 1503 | int chnlMap = 7; |
Satish kumar sugasi | da90009 | 2014-02-06 19:30:27 -0800 | [diff] [blame] | 1504 | int min_interval = 160; |
| 1505 | int max_interval = 240; |
Satish kumar sugasi | 6ee1994 | 2014-10-20 18:22:28 -0700 | [diff] [blame] | 1506 | int adv_type = 3 ;//non-connectable undirect |
Satish kumar sugasi | da90009 | 2014-02-06 19:30:27 -0800 | [diff] [blame] | 1507 | int adv_if = g_server_if_scan; |
Satish kumar sugasi | 6ee1994 | 2014-10-20 18:22:28 -0700 | [diff] [blame] | 1508 | int timeout_s = 30; |
Satish kumar sugasi | da90009 | 2014-02-06 19:30:27 -0800 | [diff] [blame] | 1509 | |
Satish kumar sugasi | 6ee1994 | 2014-10-20 18:22:28 -0700 | [diff] [blame] | 1510 | adv_if = get_int(&p, -1); |
Satish kumar sugasi | da90009 | 2014-02-06 19:30:27 -0800 | [diff] [blame] | 1511 | min_interval = get_int(&p, -1); |
| 1512 | max_interval = get_int(&p, -1); |
Satish kumar sugasi | 6ee1994 | 2014-10-20 18:22:28 -0700 | [diff] [blame] | 1513 | adv_type = get_int(&p, -1); |
| 1514 | chnlMap = get_int(&p, -1); |
| 1515 | TxPower = get_int(&p, -1); |
Nitin Shivpure | 2906055 | 2014-09-10 11:28:06 +0530 | [diff] [blame] | 1516 | timeout_s = get_int(&p, -1); |
Satish kumar sugasi | da90009 | 2014-02-06 19:30:27 -0800 | [diff] [blame] | 1517 | //To start with we are going with hard-code values. |
Nitin Shivpure | 2906055 | 2014-09-10 11:28:06 +0530 | [diff] [blame] | 1518 | Ret = sGattIfaceScan->client->multi_adv_update(adv_if, min_interval, max_interval,adv_type,chnlMap,TxPower, timeout_s); |
Satish kumar sugasi | da90009 | 2014-02-06 19:30:27 -0800 | [diff] [blame] | 1519 | } |
| 1520 | |
| 1521 | void do_le_client_adv_enable(char *p) |
| 1522 | { |
Satish kumar sugasi | 6ee1994 | 2014-10-20 18:22:28 -0700 | [diff] [blame] | 1523 | bt_status_t Ret; |
Satish kumar sugasi | da90009 | 2014-02-06 19:30:27 -0800 | [diff] [blame] | 1524 | int TxPower = 4; |
Satish kumar sugasi | 6ee1994 | 2014-10-20 18:22:28 -0700 | [diff] [blame] | 1525 | int chnlMap = 7; |
Satish kumar sugasi | da90009 | 2014-02-06 19:30:27 -0800 | [diff] [blame] | 1526 | int min_interval = 48; |
| 1527 | int max_interval = 96; |
Satish kumar sugasi | 6ee1994 | 2014-10-20 18:22:28 -0700 | [diff] [blame] | 1528 | int adv_type = 0; //connectable undirect |
| 1529 | int adv_if = g_server_if_scan; |
| 1530 | int timeout_s = 30; |
Satish kumar sugasi | 544a26e | 2014-09-05 12:36:54 -0700 | [diff] [blame] | 1531 | |
Satish kumar sugasi | 6ee1994 | 2014-10-20 18:22:28 -0700 | [diff] [blame] | 1532 | adv_if = get_int(&p, -1); |
| 1533 | min_interval = get_int(&p, -1); |
Satish kumar sugasi | da90009 | 2014-02-06 19:30:27 -0800 | [diff] [blame] | 1534 | max_interval = get_int(&p, -1); |
Satish kumar sugasi | 6ee1994 | 2014-10-20 18:22:28 -0700 | [diff] [blame] | 1535 | adv_type = get_int(&p, -1); |
| 1536 | chnlMap = get_int(&p, -1); |
| 1537 | TxPower = get_int(&p, -1); |
Nitin Shivpure | 2906055 | 2014-09-10 11:28:06 +0530 | [diff] [blame] | 1538 | timeout_s = get_int(&p, -1); |
| 1539 | Ret = sGattIfaceScan->client->multi_adv_enable(adv_if,30,60,adv_type,chnlMap,TxPower, timeout_s); |
Satish kumar sugasi | da90009 | 2014-02-06 19:30:27 -0800 | [diff] [blame] | 1540 | printf("%s:: Ret=%d \n", __FUNCTION__, Ret); |
| 1541 | } |
| 1542 | |
| 1543 | void do_le_client_adv_disable(char *p) |
| 1544 | { |
Satish kumar sugasi | 6ee1994 | 2014-10-20 18:22:28 -0700 | [diff] [blame] | 1545 | bt_status_t Ret; |
| 1546 | int adv_if = g_server_if_scan; |
Satish kumar sugasi | 544a26e | 2014-09-05 12:36:54 -0700 | [diff] [blame] | 1547 | |
Satish kumar sugasi | 6ee1994 | 2014-10-20 18:22:28 -0700 | [diff] [blame] | 1548 | adv_if = get_int(&p, -1); |
Satish kumar sugasi | da90009 | 2014-02-06 19:30:27 -0800 | [diff] [blame] | 1549 | Ret = sGattIfaceScan->client->multi_adv_disable(adv_if); |
| 1550 | printf("%s:: Ret=%d \n", __FUNCTION__, Ret); |
| 1551 | } |
| 1552 | |
Satish kumar sugasi | da90009 | 2014-02-06 19:30:27 -0800 | [diff] [blame] | 1553 | void do_le_client_configureMTU(char *p) |
| 1554 | { |
| 1555 | tGATT_STATUS Ret =0; |
| 1556 | UINT16 mtu = 23; |
| 1557 | |
| 1558 | printf("%s:: mtu :%d\n", __FUNCTION__, mtu); |
| 1559 | Ret = sGattInterface->cConfigureMTU(g_conn_id, mtu); |
| 1560 | printf("%s:: Ret=%d \n", __FUNCTION__, Ret); |
| 1561 | } |
| 1562 | |
| 1563 | void do_le_client_discover(char *p) |
| 1564 | { |
| 1565 | int uuid_len = 0; |
| 1566 | tGATT_STATUS Ret =0; |
| 1567 | tGATT_DISC_PARAM param; |
| 1568 | tGATT_DISC_TYPE disc_type; //GATT_DISC_SRVC_ALL , GATT_DISC_SRVC_BY_UUID |
| 1569 | |
| 1570 | disc_type = get_int(&p, -1); // arg1 |
| 1571 | param.s_handle = get_hex(&p, -1); // arg2 |
| 1572 | param.e_handle = get_hex(&p, -1); // arg3 |
| 1573 | |
| 1574 | uuid_len = get_int(&p, -1); // arg4 - Size in bits for the uuid (16, 32, or 128) |
| 1575 | if((16==uuid_len) || (32==uuid_len) || (128==uuid_len)) |
| 1576 | { |
| 1577 | param.service.len = uuid_len/8; |
| 1578 | } |
| 1579 | else |
| 1580 | { |
| 1581 | printf("%s::ERROR - Invalid Parameter. UUID Len should be either 16/32/128 \n",__FUNCTION__); |
| 1582 | return; |
| 1583 | } |
| 1584 | |
| 1585 | switch(param.service.len) |
| 1586 | { |
| 1587 | case 2: //16 bit uuid |
| 1588 | param.service.uu.uuid16 = get_hex(&p, -1); // arg5 |
| 1589 | break; |
| 1590 | |
| 1591 | case 4: //32 bit uuid |
| 1592 | param.service.uu.uuid32 = get_hex(&p, -1); // arg5 |
| 1593 | break; |
| 1594 | |
| 1595 | case 16: //128 bit uuid |
| 1596 | *((unsigned int*)¶m.service.uu.uuid128[12]) = get_hex(&p, -1); |
| 1597 | *((unsigned int*)¶m.service.uu.uuid128[8]) = get_hex(&p, -1); |
| 1598 | *((unsigned int*)¶m.service.uu.uuid128[4]) = get_hex(&p, -1); |
| 1599 | *((unsigned int*)param.service.uu.uuid128) = get_hex(&p, -1); //arg5 |
| 1600 | |
| 1601 | break; |
| 1602 | default: |
| 1603 | printf("%s::ERROR - Invalid Parameter. UUID Len should \n",__FUNCTION__); |
| 1604 | return; |
| 1605 | } |
| 1606 | |
| 1607 | printf("%s:: disc_type = %d, uuid=%04x \n", __FUNCTION__, disc_type, param.service.uu.uuid16); |
| 1608 | |
| 1609 | //if(FALSE == GetDiscType(p, &disc_type)) return; //TODO - add the function if user input is needed |
| 1610 | Ret = sGattInterface->cDiscover(g_conn_id, disc_type, ¶m); |
| 1611 | printf("%s:: Ret=%d \n", __FUNCTION__, Ret); |
| 1612 | } |
| 1613 | |
| 1614 | |
| 1615 | void do_le_client_read(char *p) |
| 1616 | { |
| 1617 | int i =0; |
| 1618 | int uuid_len = 0; |
| 1619 | tGATT_STATUS Ret = 0; |
| 1620 | tGATT_READ_TYPE read_type; |
| 1621 | int auth_req; |
| 1622 | tGATT_READ_PARAM readBuf;// = {GATT_AUTH_REQ_NONE, 0x201}; |
| 1623 | uint8_t uuid_128[16]; |
| 1624 | char dest[3]; |
| 1625 | tBT_UUID uuid; |
| 1626 | |
| 1627 | //Parse and copy command line arguments |
| 1628 | read_type = get_int(&p, -1); // arg2 |
| 1629 | auth_req = get_int(&p, -1); // arg2 |
| 1630 | |
| 1631 | switch(read_type) |
| 1632 | { |
| 1633 | case GATT_READ_BY_TYPE: |
| 1634 | case GATT_READ_CHAR_VALUE: |
| 1635 | |
| 1636 | readBuf.service.auth_req = auth_req; |
| 1637 | readBuf.service.s_handle = get_hex(&p, -1); // arg2 |
| 1638 | readBuf.service.e_handle = get_hex(&p, -1); // arg3 |
| 1639 | |
| 1640 | uuid_len = get_int(&p, -1); // arg4 - Size in bits for the uuid (16, 32, or 128) |
| 1641 | if((16==uuid_len) || (32==uuid_len) || (128==uuid_len)) |
| 1642 | { |
| 1643 | readBuf.service.uuid.len = uuid_len/8; |
| 1644 | } |
| 1645 | else |
| 1646 | { |
| 1647 | printf("%s::ERROR - Invalid Parameter. UUID Len should be either 16/32/128 \n",__FUNCTION__); |
| 1648 | return; |
| 1649 | } |
| 1650 | |
| 1651 | switch(readBuf.service.uuid.len) |
| 1652 | { |
| 1653 | case 2: //16 bit uuid |
| 1654 | readBuf.service.uuid.uu.uuid16 = get_hex(&p, -1); // arg5 |
| 1655 | break; |
| 1656 | |
| 1657 | case 4: //32 bit uuid |
| 1658 | readBuf.service.uuid.uu.uuid32 = get_hex(&p, -1); // arg5 |
| 1659 | break; |
| 1660 | |
| 1661 | case 16: //128 bit uuid |
| 1662 | *((unsigned int*)&readBuf.service.uuid.uu.uuid128[12]) = get_hex(&p, -1); |
| 1663 | *((unsigned int*)&readBuf.service.uuid.uu.uuid128[8]) = get_hex(&p, -1); |
| 1664 | *((unsigned int*)&readBuf.service.uuid.uu.uuid128[4]) = get_hex(&p, -1); |
| 1665 | *((unsigned int*)readBuf.service.uuid.uu.uuid128) = get_hex(&p, -1); //arg5 |
| 1666 | |
| 1667 | break; |
| 1668 | default: |
| 1669 | printf("%s::ERROR - Invalid Parameter. UUID Len should be either 4/8/32characters, which corresponds <16/32/128> bits \n",__FUNCTION__); |
| 1670 | return; |
| 1671 | } |
| 1672 | break; |
| 1673 | |
| 1674 | |
| 1675 | case GATT_READ_BY_HANDLE: |
| 1676 | readBuf.by_handle.handle = get_hex(&p, -1); |
| 1677 | readBuf.by_handle.auth_req = auth_req; |
| 1678 | break; |
| 1679 | |
| 1680 | case GATT_READ_MULTIPLE: |
| 1681 | readBuf.read_multiple.auth_req = auth_req; |
| 1682 | readBuf.read_multiple.num_handles = get_hex(&p, -1); //arg 2 |
| 1683 | if(readBuf.read_multiple.num_handles > 10) |
| 1684 | { |
| 1685 | printf(":: ERROR - invalid param. Max handle value is 10. \n"); |
| 1686 | return; |
| 1687 | } |
| 1688 | for(i=0; i<readBuf.read_multiple.num_handles; i++) |
| 1689 | { |
| 1690 | readBuf.read_multiple.handles[i] = get_hex(&p, -1); //arg 3 ... N |
| 1691 | } |
| 1692 | printf("%s:: Read by MultipleHandle \t Number of handles=%04x \n", __FUNCTION__, readBuf.read_multiple.num_handles); |
| 1693 | break; |
| 1694 | |
| 1695 | case GATT_READ_PARTIAL: |
| 1696 | readBuf.partial.auth_req = auth_req; |
| 1697 | readBuf.partial.handle = get_hex(&p, -1); //arg 2 |
| 1698 | readBuf.partial.offset = get_hex(&p, -1); //arg 3 |
| 1699 | printf("%s:: Read by Descriptor \t handle=%04x \t offset=%04x \n", __FUNCTION__, readBuf.partial.handle, readBuf.partial.offset); |
| 1700 | break; |
| 1701 | |
| 1702 | } |
| 1703 | |
| 1704 | Ret = sGattInterface->cRead(g_conn_id, read_type, &readBuf); |
| 1705 | } |
| 1706 | |
| 1707 | void copy_string(char *dest, char *source) |
| 1708 | { |
| 1709 | int i = 2; |
| 1710 | while(i) |
| 1711 | { |
| 1712 | *dest = *source; |
| 1713 | source++; |
| 1714 | dest++; |
| 1715 | i--; |
| 1716 | } |
| 1717 | *dest = '\0'; |
| 1718 | } |
| 1719 | |
| 1720 | void do_le_client_write(char *p) |
| 1721 | { |
| 1722 | int i; |
| 1723 | tGATT_STATUS Ret = 0; |
| 1724 | tGATT_WRITE_TYPE write_type; |
| 1725 | int auth_req = 0; |
| 1726 | tGATT_VALUE writeBuf;// = {GATT_AUTH_REQ_NONE, 0x201}; |
| 1727 | |
| 1728 | write_type = get_int(&p, -1); // arg1 |
| 1729 | auth_req = get_int(&p, -1); // arg2 |
| 1730 | |
| 1731 | writeBuf.conn_id = g_conn_id; |
| 1732 | writeBuf.auth_req = auth_req; |
| 1733 | writeBuf.handle = get_hex(&p, -1); // arg3 |
| 1734 | writeBuf.offset = get_hex(&p, -1); //arg4 |
| 1735 | writeBuf.len = get_int(&p, -1); //arg5 |
| 1736 | |
| 1737 | |
| 1738 | if(writeBuf.len > GATT_MAX_ATTR_LEN ) |
| 1739 | { |
| 1740 | printf("%s:: ERROR - invalid param. Max length for Write is 600 \n",__FUNCTION__); |
| 1741 | return; |
| 1742 | } |
| 1743 | memset(&(writeBuf.value[0]), 0, GATT_MAX_ATTR_LEN); |
| 1744 | for (i = 0; i < writeBuf.len; i++) |
| 1745 | { |
| 1746 | writeBuf.value[i] = get_hex_byte(&p, 0); |
| 1747 | } |
| 1748 | |
| 1749 | Ret = sGattInterface->cWrite(g_conn_id, write_type, &writeBuf); |
| 1750 | } |
| 1751 | void do_le_execute_write(char *p) |
| 1752 | { |
| 1753 | BOOLEAN is_execute; |
| 1754 | tGATT_STATUS Ret = 0; |
| 1755 | |
| 1756 | is_execute = get_int(&p, -1); // arg1 |
| 1757 | |
| 1758 | printf("%s:: is_execute=%d \n", __FUNCTION__, is_execute); |
| 1759 | Ret = sGattInterface->cExecuteWrite(g_conn_id, is_execute); |
| 1760 | printf("%s:: Ret=%d \n", __FUNCTION__, Ret); |
| 1761 | } |
| 1762 | void do_le_set_idle_timeout(char *p) |
| 1763 | { |
| 1764 | int idle_timeout; |
| 1765 | bt_bdaddr_t bd_addr = {{0}}; |
| 1766 | if(FALSE == GetBdAddr(p, &bd_addr)) return; |
| 1767 | idle_timeout = get_int(&p, -1); //arg2 |
| 1768 | sGattInterface->cSetIdleTimeout(bd_addr.address, idle_timeout); |
| 1769 | |
| 1770 | } |
| 1771 | |
| 1772 | |
| 1773 | /******************************************************************************* |
| 1774 | ** GATT SERVER API commands |
| 1775 | *******************************************************************************/ |
| 1776 | void do_le_server_register(char *p) |
| 1777 | { |
| 1778 | bt_status_t Ret; |
| 1779 | int Idx; |
| 1780 | tBT_UUID uuid; |
| 1781 | bt_uuid_t bt_uuid; |
| 1782 | skip_blanks(&p); |
| 1783 | Idx = atoi(p); |
| 1784 | switch(Idx) |
| 1785 | { |
| 1786 | case 1: |
| 1787 | uuid.len = LEN_UUID_128; |
| 1788 | memcpy(&uuid.uu.uuid128, "\x00\x00\xA0\x0C\x00\x00\x00\x00\x01\x23\x45\x67\x89\xAB\xCD\xEF", 16); //0000A00C-0000-0000-0123-456789ABCDEF |
| 1789 | memcpy(&bt_uuid.uu, "\x00\x00\xA0\x0C\x00\x00\x00\x00\x01\x23\x45\x67\x89\xAB\xCD\xEF", 16); //0000A00C-0000-0000-0123-456789ABCDEF |
| 1790 | break; |
| 1791 | case 2: |
| 1792 | uuid.len = LEN_UUID_128; |
| 1793 | memcpy(&uuid.uu.uuid128, "\x11\x22\xA0\x0C\x00\x00\x00\x00\x01\x23\x45\x67\x89\xAB\xCD\xEF", 16); //1122A00C-0000-0000-0123-456789ABCDEF |
| 1794 | memcpy(&bt_uuid.uu, "\x11\x22\xA0\x0C\x00\x00\x00\x00\x01\x23\x45\x67\x89\xAB\xCD\xEF", 16); //1122A00C-0000-0000-0123-456789ABCDEF |
| 1795 | break; |
| 1796 | default: |
| 1797 | printf("%s:: ERROR: no matching uuid \n", __FUNCTION__); |
| 1798 | return; |
| 1799 | } |
| 1800 | |
| 1801 | if(Btif_gatt_layer) |
| 1802 | { |
| 1803 | Ret = sGattIfaceScan->server->register_server(&bt_uuid); |
| 1804 | } |
| 1805 | else |
| 1806 | { |
| 1807 | g_server_if = sGattInterface->Register(&uuid, &sGattCB); |
| 1808 | printf("%s:: g_server_if=%d \n", __FUNCTION__, g_server_if); |
| 1809 | } |
| 1810 | |
| 1811 | } |
| 1812 | |
| 1813 | void do_le_server_deregister(char *p) |
| 1814 | { |
| 1815 | bt_status_t Ret; |
| 1816 | if(0 == g_server_if) |
| 1817 | { |
| 1818 | printf("%s:: ERROR: no application registered\n", __FUNCTION__); |
| 1819 | return; |
| 1820 | } |
| 1821 | sGattInterface->Deregister(g_server_if); |
| 1822 | Ret = sGattIfaceScan->server->unregister_server(g_server_if_scan); |
| 1823 | printf("%s:: \n", __FUNCTION__); |
| 1824 | } |
| 1825 | |
| 1826 | void do_le_server_add_service(char *p) |
| 1827 | { |
| 1828 | bt_status_t Ret = 0; |
| 1829 | |
| 1830 | //Later take this value as cmd line |
| 1831 | btgatt_srvc_id_t srvc_id; |
| 1832 | memcpy(&srvc_id.id.uuid.uu, "\x00\x00\x18\x00\x00\x00\x10\x00\x80\x00\x00\x80\x5f\x9b\x34\xfb", 16); //00001800-0000-1000-8000-00805f9b34fb |
| 1833 | |
| 1834 | |
| 1835 | srvc_id.id.inst_id = 1;// |
| 1836 | srvc_id.is_primary = BTGATT_SERVICE_TYPE_PRIMARY; // BTGATT_SERVICE_TYPE_SECONDARY |
| 1837 | Ret = sGattIfaceScan->server->add_service(g_server_if_scan, &srvc_id, 1/*num_handles*/); |
| 1838 | } |
| 1839 | |
| 1840 | void do_le_server_connect (char *p) |
| 1841 | { |
| 1842 | BOOLEAN Ret; |
| 1843 | bt_bdaddr_t bd_addr = {{0}}; |
| 1844 | if(FALSE == GetBdAddr(p, &bd_addr)) return; |
| 1845 | Ret = sGattIfaceScan->server->connect(g_server_if_scan, &bd_addr, TRUE, BT_TRANSPORT_LE); |
| 1846 | } |
| 1847 | |
| 1848 | void do_le_server_connect_auto (char *p) |
| 1849 | { |
| 1850 | BOOLEAN Ret; |
| 1851 | bt_bdaddr_t bd_addr = {{0}}; |
| 1852 | if(FALSE == GetBdAddr(p, &bd_addr)) return; |
| 1853 | Ret = sGattIfaceScan->server->connect(g_server_if_scan, &bd_addr, FALSE, BT_TRANSPORT_LE); |
| 1854 | } |
| 1855 | |
| 1856 | |
| 1857 | void do_le_server_disconnect (char *p) |
| 1858 | { |
| 1859 | bt_status_t Ret; |
| 1860 | bt_bdaddr_t bd_addr = {{0}}; |
| 1861 | if(FALSE == GetBdAddr(p, &bd_addr)) return; |
| 1862 | Ret = sGattIfaceScan->server->disconnect(g_server_if_scan, &bd_addr, g_conn_id); |
| 1863 | } |
| 1864 | |
| 1865 | /************************************************** |
| 1866 | **L2CAP for BR/EDR conn |
| 1867 | ***************************************************/ |
| 1868 | |
| 1869 | |
| 1870 | |
| 1871 | void do_l2cap_init(char *p) |
| 1872 | { |
| 1873 | |
| 1874 | char *value = NULL; |
| 1875 | |
| 1876 | memset(&tl2cap_cfg_info, 0, sizeof(tl2cap_cfg_info)); |
| 1877 | //Use macros for the constants |
| 1878 | tl2cap_cfg_info.mtu_present = TRUE; |
| 1879 | tl2cap_cfg_info.mtu = g_imtu; |
| 1880 | tl2cap_cfg_info.flush_to_present = TRUE; |
| 1881 | tl2cap_cfg_info.flush_to = 0xffff; |
| 1882 | //use other param if needed |
| 1883 | tl2cap_cfg_info.fcr_present = g_Fcr_Present; |
| 1884 | tl2cap_cfg_info.fcr.mode = g_Fcr_Mode; |
| 1885 | tl2cap_cfg_info.fcs = 0; |
| 1886 | tl2cap_cfg_info.fcs_present = 1; |
| 1887 | |
| 1888 | if(L2CAP_FCR_ERTM_MODE == tl2cap_cfg_info.fcr.mode) |
| 1889 | { |
| 1890 | tl2cap_cfg_info.fcr = ertm_fcr_opts_def; |
| 1891 | } |
| 1892 | else if(L2CAP_FCR_STREAM_MODE == tl2cap_cfg_info.fcr.mode) |
| 1893 | { |
| 1894 | tl2cap_cfg_info.fcr = stream_fcr_opts_def; |
| 1895 | } |
| 1896 | tl2cap_cfg_info.fcr.tx_win_sz = 3; |
| 1897 | //Initialize ERTM Parameters |
| 1898 | t_ertm_info.preferred_mode = g_Fcr_Mode; |
| 1899 | t_ertm_info.allowed_modes = g_Ertm_AllowedMode; |
| 1900 | t_ertm_info.user_rx_pool_id = HCI_ACL_POOL_ID; |
| 1901 | t_ertm_info.user_tx_pool_id = HCI_ACL_POOL_ID; |
| 1902 | t_ertm_info.fcr_rx_pool_id = L2CAP_FCR_RX_POOL_ID; |
| 1903 | t_ertm_info.fcr_tx_pool_id = L2CAP_FCR_TX_POOL_ID; |
| 1904 | //Load L2cap Interface |
| 1905 | sL2capInterface->Init(&l2test_l2c_appl); |
| 1906 | } |
| 1907 | |
| 1908 | |
| 1909 | |
| 1910 | static int l2c_pair(char *p) |
| 1911 | { |
| 1912 | bt_bdaddr_t bd_addr = {{0}}; |
Satish kumar sugasi | 544a26e | 2014-09-05 12:36:54 -0700 | [diff] [blame] | 1913 | int transport = BT_TRANSPORT_BR_EDR; |
| 1914 | transport = get_int(&p, -1); |
Satish kumar sugasi | da90009 | 2014-02-06 19:30:27 -0800 | [diff] [blame] | 1915 | GetBdAddr(p, &bd_addr); |
Satish kumar sugasi | 544a26e | 2014-09-05 12:36:54 -0700 | [diff] [blame] | 1916 | if(BT_STATUS_SUCCESS != sBtInterface->create_bond(&bd_addr,transport)) |
Satish kumar sugasi | da90009 | 2014-02-06 19:30:27 -0800 | [diff] [blame] | 1917 | { |
| 1918 | printf("Failed to Initiate Pairing \n"); |
| 1919 | return FALSE; |
| 1920 | } |
Satish kumar sugasi | 544a26e | 2014-09-05 12:36:54 -0700 | [diff] [blame] | 1921 | sleep(20); |
Satish kumar sugasi | da90009 | 2014-02-06 19:30:27 -0800 | [diff] [blame] | 1922 | return TRUE; |
| 1923 | } |
| 1924 | |
| 1925 | static UINT16 do_l2cap_connect(bt_bdaddr_t * bd_addr) |
| 1926 | { |
| 1927 | |
| 1928 | if((L2CAP_FCR_STREAM_MODE == g_Fcr_Mode) || (L2CAP_FCR_ERTM_MODE == g_Fcr_Mode)) { |
| 1929 | return sL2capInterface->ErtmConnectReq(g_PSM, bd_addr->address, &t_ertm_info); |
| 1930 | } else { |
| 1931 | return sL2capInterface->Connect(g_PSM, bd_addr); |
| 1932 | } |
| 1933 | } |
| 1934 | |
| 1935 | static void l2c_connect(bt_bdaddr_t *bd_addr) |
| 1936 | { |
| 1937 | do_l2cap_connect(bd_addr); |
| 1938 | } |
| 1939 | |
| 1940 | |
| 1941 | BOOLEAN do_l2cap_disconnect(char *p) |
| 1942 | { |
| 1943 | return sL2capInterface->DisconnectReq(g_lcid); |
| 1944 | } |
| 1945 | |
| 1946 | |
| 1947 | |
flintman | fb976bd | 2015-10-02 19:10:17 -0400 | [diff] [blame] | 1948 | #if SMP_INCLUDED == TRUE |
Satish kumar sugasi | da90009 | 2014-02-06 19:30:27 -0800 | [diff] [blame] | 1949 | /******************************************************************************* |
| 1950 | ** SMP API commands |
| 1951 | *******************************************************************************/ |
| 1952 | void do_smp_init(char *p) |
| 1953 | { |
| 1954 | sSmpIface->init(); |
| 1955 | sleep(1); |
| 1956 | sSmpIface->Register(SMP_cb); |
| 1957 | sleep(1); |
| 1958 | } |
| 1959 | |
| 1960 | void do_smp_pair(char *p) |
| 1961 | { |
| 1962 | tSMP_STATUS Ret = 0; |
| 1963 | bt_bdaddr_t bd_addr = {{0}}; |
| 1964 | if(FALSE == GetBdAddr(p, &bd_addr)) return; |
| 1965 | Ret = sSmpIface->Pair(bd_addr.address); |
| 1966 | } |
| 1967 | |
| 1968 | void do_smp_pair_cancel(char *p) |
| 1969 | { |
| 1970 | BOOLEAN Ret = 0; |
| 1971 | bt_bdaddr_t bd_addr = {{0}}; |
| 1972 | if(FALSE == GetBdAddr(p, &bd_addr)) return; |
| 1973 | Ret = sSmpIface->PairCancel(bd_addr.address); |
| 1974 | printf("%s:: Ret=%d \n", __FUNCTION__, Ret); |
| 1975 | } |
| 1976 | |
| 1977 | void do_smp_security_grant(char *p) |
| 1978 | { |
| 1979 | UINT8 res; |
| 1980 | bt_bdaddr_t bd_addr = {{0}}; |
| 1981 | if(FALSE == GetBdAddr(p, &bd_addr)) return; //arg1 |
| 1982 | res = get_int(&p, -1); // arg2 |
| 1983 | sSmpIface->SecurityGrant(bd_addr.address, res); |
| 1984 | printf("%s:: Ret=%d \n", __FUNCTION__,res); |
| 1985 | } |
| 1986 | |
| 1987 | void do_smp_passkey_reply(char *p) |
| 1988 | { |
| 1989 | UINT32 passkey; |
| 1990 | UINT8 res; |
| 1991 | bt_bdaddr_t bd_addr = {{0}}; |
| 1992 | if(FALSE == GetBdAddr(p, &bd_addr)) return; //arg1 |
| 1993 | printf("get res value\n"); |
| 1994 | res = get_int(&p, -1); // arg2 |
| 1995 | printf("res value=%d\n", res); |
| 1996 | passkey = get_int(&p, -1); // arg3 |
| 1997 | printf("passkey value=%d\n", passkey); |
| 1998 | sSmpIface->PasskeyReply(bd_addr.address, res, passkey); |
| 1999 | printf("%s:: Ret=%d \n", __FUNCTION__,res); |
| 2000 | } |
flintman | fb976bd | 2015-10-02 19:10:17 -0400 | [diff] [blame] | 2001 | #endif |
Satish kumar sugasi | da90009 | 2014-02-06 19:30:27 -0800 | [diff] [blame] | 2002 | |
| 2003 | void do_smp_encrypt(char *p) |
| 2004 | { |
| 2005 | BOOLEAN Ret = 0; |
| 2006 | UINT8 res; |
| 2007 | bt_bdaddr_t bd_addr = {{0}}; |
| 2008 | if(FALSE == GetBdAddr(p, &bd_addr)) return; //arg1 |
| 2009 | res = get_int(&p, -1); // arg2 |
| 2010 | printf("%s:: Ret=%d \n", __FUNCTION__, Ret); |
| 2011 | } |
| 2012 | |
| 2013 | void do_le_gap_conn_param_update(char *p) |
| 2014 | { |
| 2015 | UINT16 attr_uuid = GATT_UUID_GAP_PREF_CONN_PARAM; |
| 2016 | //attr_uuid = get_int(&p, -1); |
| 2017 | tGAP_BLE_ATTR_VALUE attr_value; |
| 2018 | attr_value.conn_param.int_min = 50; |
| 2019 | attr_value.conn_param.int_max = 70; |
| 2020 | attr_value.conn_param.latency = 0; |
| 2021 | attr_value.conn_param.sp_tout = 10; |
| 2022 | bt_bdaddr_t bd_addr = {{0}}; |
| 2023 | if(FALSE == GetBdAddr(p, &bd_addr)) return; //arg1 |
| 2024 | //attr_uuid = get_hex(&p, -1); |
| 2025 | //L2CA_UpdateBleConnParams(bd_addr.address, 50, 70, 0, 1000); |
| 2026 | printf("stage 1\n"); |
| 2027 | sGapInterface->Gap_BleAttrDBUpdate(bd_addr.address, 50, 70, 0, 1000); |
| 2028 | printf("%s:: GAP connection parameter Update\n", __FUNCTION__); |
| 2029 | |
| 2030 | } |
| 2031 | void do_le_gap_attr_init(char *p) |
| 2032 | { |
| 2033 | sGapInterface->Gap_AttrInit(); |
| 2034 | printf("%s:: GAP Initialization\n", __FUNCTION__); |
| 2035 | |
| 2036 | } |
| 2037 | |
| 2038 | void do_le_gap_set_disc(char *p) |
| 2039 | { |
Nitin Shivpure | 2906055 | 2014-09-10 11:28:06 +0530 | [diff] [blame] | 2040 | UINT16 Ret = 0; |
Satish kumar sugasi | da90009 | 2014-02-06 19:30:27 -0800 | [diff] [blame] | 2041 | UINT16 mode; |
| 2042 | UINT16 duration; |
| 2043 | UINT16 interval; |
| 2044 | |
| 2045 | mode = get_int(&p, -1); |
| 2046 | if(1 == mode) mode = GAP_NON_DISCOVERABLE; |
| 2047 | else if(2 == mode) mode = GAP_LIMITED_DISCOVERABLE; |
| 2048 | else mode = GAP_GENERAL_DISCOVERABLE; |
| 2049 | |
| 2050 | duration = get_int(&p, -1); |
| 2051 | if((12 > duration) || (duration > 1000)) duration = 0; //if 0 is passed, stack will take 12 as default |
| 2052 | |
| 2053 | interval = get_int(&p, -1); |
| 2054 | if((12 > interval) || (interval > 1000)) interval = 0; //if 0 is passed, stack will take 800 as default |
| 2055 | |
Nitin Shivpure | 2906055 | 2014-09-10 11:28:06 +0530 | [diff] [blame] | 2056 | |
| 2057 | |
Satish kumar sugasi | da90009 | 2014-02-06 19:30:27 -0800 | [diff] [blame] | 2058 | sGapInterface->Gap_SetDiscoverableMode(mode, duration, interval); |
| 2059 | printf("%s:: Ret=%d\n", __FUNCTION__, Ret); |
| 2060 | } |
| 2061 | |
| 2062 | void do_le_gap_set_conn(char *p) |
| 2063 | { |
Nitin Shivpure | 2906055 | 2014-09-10 11:28:06 +0530 | [diff] [blame] | 2064 | UINT16 Ret=0; |
Satish kumar sugasi | da90009 | 2014-02-06 19:30:27 -0800 | [diff] [blame] | 2065 | UINT16 mode; |
| 2066 | UINT16 duration; |
| 2067 | UINT16 interval; |
| 2068 | |
| 2069 | mode = get_int(&p, -1); |
| 2070 | if(1 == mode) |
| 2071 | mode = GAP_NON_CONNECTABLE; |
| 2072 | else |
| 2073 | mode = GAP_CONNECTABLE; |
| 2074 | |
| 2075 | duration = get_int(&p, -1); |
| 2076 | if((12 > duration) || (duration > 1000)) duration = 0; //if 0 is passed, stack will take 12 as default |
| 2077 | |
| 2078 | interval = get_int(&p, -1); |
| 2079 | if((12 > interval) || (interval > 1000)) interval = 0; //if 0 is passed, stack will take 800 as default |
| 2080 | |
| 2081 | sGapInterface->Gap_SetConnectableMode(mode, duration, interval); |
| 2082 | printf("%s:: Ret=%d\n", __FUNCTION__, Ret); |
| 2083 | } |
| 2084 | |
| 2085 | void do_l2cap_send_data_cid(char *p) |
| 2086 | { |
| 2087 | UINT16 cid = 0; |
| 2088 | BT_HDR bt_hdr; |
| 2089 | UINT16 Ret = 0; |
| 2090 | bt_bdaddr_t bd_addr = {{0}}; |
| 2091 | if(FALSE == GetBdAddr(p, &bd_addr)) return; //arg1 |
| 2092 | cid = get_int(&p, -1); // arg2 |
| 2093 | |
| 2094 | bt_hdr.event = 0; |
| 2095 | bt_hdr.len = 1; |
| 2096 | bt_hdr.offset = 0; |
| 2097 | bt_hdr.layer_specific = 0; |
| 2098 | |
| 2099 | |
| 2100 | Ret = sL2capInterface->SendFixedChnlData(cid, bd_addr.address, &bt_hdr); |
| 2101 | printf("%s:: Ret=%d \n", __FUNCTION__, Ret); |
| 2102 | |
| 2103 | } |
| 2104 | /******************************************************************* |
| 2105 | * |
| 2106 | * CONSOLE COMMAND TABLE |
| 2107 | * |
| 2108 | */ |
| 2109 | |
| 2110 | const t_cmd console_cmd_list[] = |
| 2111 | { |
| 2112 | /* |
| 2113 | * INTERNAL |
| 2114 | */ |
| 2115 | |
| 2116 | { "help", do_help, "lists all available console commands", 0 }, |
| 2117 | { "quit", do_quit, "", 0}, |
| 2118 | |
| 2119 | /* |
| 2120 | * API CONSOLE COMMANDS |
| 2121 | */ |
| 2122 | |
| 2123 | /* Init and Cleanup shall be called automatically */ |
| 2124 | { "enable", do_enable, ":: enables bluetooth", 0 }, |
| 2125 | { "disable", do_disable, ":: disables bluetooth", 0 }, |
| 2126 | { "dut_mode_configure", do_dut_mode_configure, ":: DUT mode - 1 to enter,0 to exit", 0 }, |
| 2127 | { "c_register", do_le_client_register, "::UUID: 1<1111..> 2<12323..> 3<321111..>", 0 }, |
| 2128 | { "c_deregister", do_le_client_deregister, "::UUID: 1<1111..> 2<12323..> 3<321111..>", 0 }, |
| 2129 | { "c_connect", do_le_client_connect, ":: transport-type<0,1...> , BdAddr<00112233445566>", 0 }, |
Satish kumar sugasi | 87a7690 | 2014-10-03 17:07:00 -0700 | [diff] [blame] | 2130 | { "c_refresh", do_le_client_refresh, ":: BdAddr<00112233445566>", 0 }, |
Satish kumar sugasi | c470d8c | 2014-10-20 14:09:05 -0700 | [diff] [blame] | 2131 | { "c_conn_param_update", do_le_conn_param_update, ":: int min_interval, int max_interval,int latency, BdAddr<00112233445566>", 0 }, |
Satish kumar sugasi | da90009 | 2014-02-06 19:30:27 -0800 | [diff] [blame] | 2132 | { "c_connect_auto", do_le_client_connect_auto, ":: BdAddr<00112233445566>", 0 }, |
| 2133 | { "c_disconnect", do_le_client_disconnect, ":: BdAddr<00112233445566>", 0 }, |
| 2134 | { "c_configureMTU", do_le_client_configureMTU, ":: 23", 0 }, |
| 2135 | { "c_discover", do_le_client_discover, "type(1-PrimaryService, 2-PrimaryService using UUID, 3-Included Service, 4-Characteristic, 5-Characteristic Descriptor) \ |
| 2136 | \n\t s.handle(hex) e.handle(hex) UUIDLen(16/32/128) UUID(hex)", 0 }, |
| 2137 | { "c_read", do_le_client_read, "Type(1-ByType, 2-ByHandle, 3-ByMultiple, 4-CharValue, 5-Partial (blob)) Auth_Req \ |
| 2138 | \n\t ByType :: s.handle(hex) e.handle(hex) UUIDLen(16/32/128) UUID(hex) \ |
| 2139 | \n\t ByHandle :: Handle(hex) \ |
| 2140 | \n\t ByMultiple :: NumOfHandle<1-10> Handle_1(hex) Handle_2(hex) ... Handle_N(hex) \ |
| 2141 | \n\t CharValue :: s.handle(hex) e.handle(hex) UUIDLen(16/32/128) UUID(hex) \ |
| 2142 | \n\t Partial/Blob :: Handle(hex) Offset(hex)", 0 }, |
| 2143 | { "c_write", do_le_client_write, "Type(1-No response, 2-write, 3-prepare write), Auth_req, Handle, Offset, Len(0-600), Value(hex)", 0 }, |
| 2144 | { "c_execute_write", do_le_execute_write, "is_execute", 0 }, |
| 2145 | { "c_scan_start", do_le_client_scan_start, "::", 0 }, |
| 2146 | { "c_scan_stop", do_le_client_scan_stop, "::", 0 }, |
Satish kumar sugasi | 87a7690 | 2014-10-03 17:07:00 -0700 | [diff] [blame] | 2147 | { "c_set_adv_data", do_le_client_multi_adv_set_inst_data, "::EnableScanrsp<0/1>, IncludeName<0/1> IncludeTxPower<0/1>", 0 }, |
Nitin Shivpure | 2906055 | 2014-09-10 11:28:06 +0530 | [diff] [blame] | 2148 | { "start_advertising", do_le_client_adv_enable, "::int client_if,nt min_interval,int max_interval,int adv_type,int chnl_map, int tx_power timeout",0}, |
Satish kumar sugasi | 87a7690 | 2014-10-03 17:07:00 -0700 | [diff] [blame] | 2149 | { "c_adv_update", do_le_client_adv_update, "::int min_interval,int max_interval,int adv_type,int chnl_map, int tx_power, int timeout",0}, |
| 2150 | { "stop_advertising", do_le_client_adv_disable, "::int adv_if",0}, |
Satish kumar sugasi | da90009 | 2014-02-06 19:30:27 -0800 | [diff] [blame] | 2151 | { "c_set_idle_timeout", do_le_set_idle_timeout, "bd_addr, time_out(int)", 0 }, |
| 2152 | { "c_gap_attr_init", do_le_gap_attr_init, "::", 0 }, |
| 2153 | { "c_gap_conn_param_update", do_le_gap_conn_param_update, "::", 0 }, |
Satish kumar sugasi | da90009 | 2014-02-06 19:30:27 -0800 | [diff] [blame] | 2154 | |
| 2155 | { "s_register", do_le_server_register, "::UUID: 1<1111..> 2<12323..> 3<321111..>", 0 }, |
| 2156 | { "s_connect", do_le_server_connect, ":: BdAddr<00112233445566>", 0 }, |
| 2157 | { "s_connect_auto", do_le_server_connect_auto, ":: BdAddr<00112233445566>", 0 }, |
| 2158 | { "s_disconnect", do_le_server_disconnect, ":: BdAddr<00112233445566>", 0 }, |
| 2159 | { "s_add_service", do_le_server_add_service, "::", 0 }, |
| 2160 | |
| 2161 | { "pair", do_pairing, ":: BdAddr<00112233445566>", 0 }, |
flintman | fb976bd | 2015-10-02 19:10:17 -0400 | [diff] [blame] | 2162 | #if SMP_INCLUDED == TRUE |
Satish kumar sugasi | da90009 | 2014-02-06 19:30:27 -0800 | [diff] [blame] | 2163 | { "smp_init", do_smp_init, "::", 0 }, //Here itself we will register. |
| 2164 | { "smp_pair", do_smp_pair, ":: BdAddr<00112233445566>", 0 }, |
| 2165 | { "smp_pair_cancel", do_smp_pair_cancel, ":: BdAddr<00112233445566>", 0 }, |
| 2166 | { "smp_security_grant", do_smp_security_grant, ":: BdAddr<00112233445566>, res<>", 0 }, |
| 2167 | { "smp_passkey_reply", do_smp_passkey_reply, ":: BdAddr<00112233445566>, res<>, passkey<>", 0 }, |
flintman | fb976bd | 2015-10-02 19:10:17 -0400 | [diff] [blame] | 2168 | #endif |
Satish kumar sugasi | da90009 | 2014-02-06 19:30:27 -0800 | [diff] [blame] | 2169 | //{ "smp_encrypt", do_smp_encrypt, "::", 0 }, |
| 2170 | { "l2cap_send_data_cid", do_l2cap_send_data_cid, ":: BdAddr<00112233445566>, CID<>", 0 }, |
| 2171 | |
Satish kumar sugasi | da90009 | 2014-02-06 19:30:27 -0800 | [diff] [blame] | 2172 | { "set_local_name", do_set_localname, ":: setName<name>", 0 }, |
| 2173 | /* add here */ |
| 2174 | |
| 2175 | /* last entry */ |
| 2176 | {NULL, NULL, "", 0}, |
| 2177 | }; |
| 2178 | |
| 2179 | /* |
| 2180 | * Main console command handler |
| 2181 | */ |
| 2182 | |
| 2183 | static void process_cmd(char *p, unsigned char is_job) |
| 2184 | { |
| 2185 | char cmd[2048]; |
| 2186 | int i = 0; |
| 2187 | bt_pin_code_t pincode; |
| 2188 | char *p_saved = p; |
| 2189 | |
| 2190 | get_str(&p, cmd); |
| 2191 | |
| 2192 | /* table commands */ |
| 2193 | while (console_cmd_list[i].name != NULL) |
| 2194 | { |
| 2195 | if (is_cmd(console_cmd_list[i].name)) |
| 2196 | { |
| 2197 | if (!is_job && console_cmd_list[i].is_job) |
| 2198 | create_cmdjob(p_saved); |
| 2199 | else |
| 2200 | { |
| 2201 | console_cmd_list[i].handler(p); |
| 2202 | } |
| 2203 | return; |
| 2204 | } |
| 2205 | i++; |
| 2206 | } |
| 2207 | //pin key |
| 2208 | if(cmd[6] == '.') { |
| 2209 | for(i=0; i<6; i++) { |
| 2210 | pincode.pin[i] = cmd[i]; |
| 2211 | } |
Nitin Shivpure | 2906055 | 2014-09-10 11:28:06 +0530 | [diff] [blame] | 2212 | if(BT_STATUS_SUCCESS != sBtInterface->pin_reply(remote_bd_address, TRUE, strlen((const char*)pincode.pin), &pincode)) { |
Satish kumar sugasi | da90009 | 2014-02-06 19:30:27 -0800 | [diff] [blame] | 2213 | printf("Pin Reply failed\n"); |
| 2214 | } |
| 2215 | //flush the char for pinkey |
| 2216 | cmd[6] = 0; |
| 2217 | } |
| 2218 | else { |
| 2219 | bdt_log("%s : unknown command\n", p_saved); |
| 2220 | do_help(NULL); |
| 2221 | } |
| 2222 | } |
| 2223 | |
| 2224 | int main (int argc, char * argv[]) |
| 2225 | { |
| 2226 | int opt; |
| 2227 | char cmd[2048]; |
| 2228 | int args_processed = 0; |
| 2229 | int pid = -1; |
| 2230 | |
| 2231 | static btgatt_callbacks_t sGatt_cb = {sizeof(btgatt_callbacks_t), &sGattClient_cb, &sGattServer_cb}; |
| 2232 | |
| 2233 | config_permissions(); |
| 2234 | bdt_log("\n:::::::::::::::::::::::::::::::::::::::::::::::::::"); |
| 2235 | bdt_log(":: Bluedroid test app starting"); |
| 2236 | |
| 2237 | if ( HAL_load() < 0 ) { |
| 2238 | perror("HAL failed to initialize, exit\n"); |
| 2239 | unlink(PID_FILE); |
| 2240 | exit(0); |
| 2241 | } |
| 2242 | |
| 2243 | setup_test_env(); |
| 2244 | |
| 2245 | /* Automatically perform the init */ |
| 2246 | bdt_init(); |
| 2247 | sleep(5); |
| 2248 | bdt_enable(); |
| 2249 | sleep(5); |
Nitin Shivpure | 2906055 | 2014-09-10 11:28:06 +0530 | [diff] [blame] | 2250 | bdt_log("Get SMP IF BT Interface = %x \n", sBtInterface); |
flintman | fb976bd | 2015-10-02 19:10:17 -0400 | [diff] [blame] | 2251 | #if BTA_GATT_INCLUDED == TRUE |
Nitin Shivpure | 2906055 | 2014-09-10 11:28:06 +0530 | [diff] [blame] | 2252 | sGattInterface = sBtInterface->get_testapp_interface(TEST_APP_GATT); |
flintman | fb976bd | 2015-10-02 19:10:17 -0400 | [diff] [blame] | 2253 | #endif |
| 2254 | #if SMP_INCLUDED == TRUE |
Satish kumar sugasi | da90009 | 2014-02-06 19:30:27 -0800 | [diff] [blame] | 2255 | sSmpIface = sBtInterface->get_testapp_interface(TEST_APP_SMP); |
flintman | fb976bd | 2015-10-02 19:10:17 -0400 | [diff] [blame] | 2256 | #endif |
Satish kumar sugasi | da90009 | 2014-02-06 19:30:27 -0800 | [diff] [blame] | 2257 | bdt_log("Get GAP IF"); |
| 2258 | sGapInterface = sBtInterface->get_testapp_interface(TEST_APP_GAP); |
| 2259 | |
| 2260 | bdt_log("Get GATT IF"); |
| 2261 | sGattIfaceScan = sBtInterface->get_profile_interface(BT_PROFILE_GATT_ID); |
| 2262 | |
| 2263 | bdt_log("Get L2CAP IF"); |
| 2264 | sL2capInterface = sBtInterface->get_testapp_interface(TEST_APP_L2CAP); |
Satish kumar sugasi | 544a26e | 2014-09-05 12:36:54 -0700 | [diff] [blame] | 2265 | |
Satish kumar sugasi | da90009 | 2014-02-06 19:30:27 -0800 | [diff] [blame] | 2266 | sGattIfaceScan->init(&sGatt_cb); |
| 2267 | bdt_log("GATT IF INIT Done"); |
Satish kumar sugasi | 544a26e | 2014-09-05 12:36:54 -0700 | [diff] [blame] | 2268 | |
Satish kumar sugasi | 6ee1994 | 2014-10-20 18:22:28 -0700 | [diff] [blame] | 2269 | printf("\n Before l2cap init\n"); |
| 2270 | do_l2cap_init(NULL); |
| 2271 | printf("\n after l2cap init\n"); |
Satish kumar sugasi | da90009 | 2014-02-06 19:30:27 -0800 | [diff] [blame] | 2272 | |
| 2273 | while(!main_done) |
| 2274 | { |
| 2275 | char line[2048]; |
| 2276 | |
| 2277 | /* command prompt */ |
| 2278 | printf( ">" ); |
| 2279 | fflush(stdout); |
| 2280 | |
| 2281 | fgets (line, 2048, stdin); |
| 2282 | |
| 2283 | if (line[0]!= '\0') |
| 2284 | { |
| 2285 | /* remove linefeed */ |
| 2286 | line[strlen(line)-1] = 0; |
| 2287 | |
| 2288 | process_cmd(line, 0); |
| 2289 | memset(line, '\0', 2048); |
| 2290 | } |
| 2291 | } |
| 2292 | |
| 2293 | /* FIXME: Commenting this out as for some reason, the application does not exit otherwise*/ |
| 2294 | //bdt_cleanup(); |
| 2295 | |
| 2296 | HAL_unload(); |
| 2297 | |
| 2298 | bdt_log(":: Bluedroid test app terminating"); |
| 2299 | |
| 2300 | return 0; |
| 2301 | } |
| 2302 | |
| 2303 | |
| 2304 | int GetBdAddr(char *p, bt_bdaddr_t *pbd_addr) |
| 2305 | { |
| 2306 | char Arr[13] = {0}; |
| 2307 | char *pszAddr = NULL; |
| 2308 | uint8_t k1 = 0; |
| 2309 | uint8_t k2 = 0; |
Nitin Shivpure | 2906055 | 2014-09-10 11:28:06 +0530 | [diff] [blame] | 2310 | uint8_t i; |
Satish kumar sugasi | da90009 | 2014-02-06 19:30:27 -0800 | [diff] [blame] | 2311 | char *t = NULL; |
| 2312 | |
| 2313 | skip_blanks(&p); |
| 2314 | |
| 2315 | printf("Input=%s\n", p); |
| 2316 | |
| 2317 | if(12 > strlen(p)) |
| 2318 | { |
| 2319 | printf("\nInvalid Bd Address. Format[112233445566]\n"); |
| 2320 | return FALSE; |
| 2321 | } |
| 2322 | memcpy(Arr, p, 12); |
| 2323 | |
| 2324 | for(i=0; i<12; i++) |
| 2325 | { |
| 2326 | Arr[i] = tolower(Arr[i]); |
| 2327 | } |
| 2328 | pszAddr = Arr; |
| 2329 | |
| 2330 | for(i=0; i<6; i++) |
| 2331 | { |
| 2332 | k1 = (uint8_t) ( (*pszAddr >= 'a') ? ( 10 + (uint8_t)( *pszAddr - 'a' )) : (*pszAddr - '0') ); |
| 2333 | pszAddr++; |
| 2334 | k2 = (uint8_t) ( (*pszAddr >= 'a') ? ( 10 + (uint8_t)( *pszAddr - 'a' )) : (*pszAddr - '0') ); |
| 2335 | pszAddr++; |
| 2336 | |
| 2337 | if ( (k1>15)||(k2>15) ) |
| 2338 | { |
| 2339 | return FALSE; |
| 2340 | } |
| 2341 | pbd_addr->address[i] = (k1<<4 | k2); |
| 2342 | } |
| 2343 | return TRUE; |
| 2344 | } |
| 2345 | #endif //TEST_APP_INTERFACE |