blob: 421b3fde7879d5efe92295db3d73abbcdf683e0e [file] [log] [blame]
Matadeen Mishra72153522016-05-11 21:16:09 -07001/*
2 * Copyright (c) 2013, The Linux Foundation. All rights reserved.
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#ifdef TEST_APP_INTERFACE
30#ifndef ANDROID_INCLUDE_BT_TESTAPP_H
31#define ANDROID_INCLUDE_BT_TESTAPP_H
32#include <stdio.h>
33#include <dlfcn.h>
34#include <stdlib.h>
35#include <errno.h>
36#include <string.h>
37#include <pthread.h>
38#include <unistd.h>
39#include <ctype.h>
40#include <fcntl.h>
41#include <sys/prctl.h>
42#include <linux/capability.h>
43#include <arpa/inet.h>
44#include <netinet/in.h>
45#include <netdb.h>
46#include <private/android_filesystem_config.h>
47#include <android/log.h>
48#include <hardware/bluetooth.h>
49#include "l2c_api.h"
50#include "sdp_api.h"
51#include "gatt_api.h"
52#include "gap_api.h"
53#include "mca_api.h"
54#include <hardware/hardware.h>
55#include "btm_api.h"
56
57__BEGIN_DECLS
58
59typedef void (tREMOTE_DEVICE_NAME_CB) (void *p1);
60
61enum {
62 SUCCESS,
63 FAIL
64};
65
66typedef enum {
67 DUMMY,
68 ALL,
69 SPP,
70 FTP,
71 OPP,
72 MAP,
73 PBAP,
74 DUN,
75 NOT_SUPPORTED,
76}profileName;
77typedef enum {
78 TEST_APP_L2CAP,
79 TEST_APP_RFCOMM,
Satish kumar sugasi2a86d962015-04-10 12:46:02 -070080 TEST_APP_MCAP,
81 TEST_APP_GATT,
82 TEST_APP_GAP,
83 TEST_APP_SMP
Matadeen Mishra72153522016-05-11 21:16:09 -070084} test_app_profile;
85typedef struct {
86
87 /** set to sizeof(Btl2capInterface) */
88 size_t size;
89 /** Register the L2cap callbacks */
90 bt_status_t (*Init)(tL2CAP_APPL_INFO* callbacks);
91 bt_status_t (*RegisterPsm)(UINT16 psm, BOOLEAN conn_type, UINT16 sec_level);
92 bt_status_t (*Deregister)(UINT16 psm);
93 UINT16 (*AllocatePsm)(void);
94 UINT16 (*Connect)(UINT16 psm, bt_bdaddr_t *bd_addr);
95 BOOLEAN (*ConnectRsp)(BD_ADDR p_bd_addr, UINT8 id, UINT16 lcid, UINT16 result, UINT16 status);
96 UINT16 (*ErtmConnectReq)(UINT16 psm, BD_ADDR p_bd_addr, tL2CAP_ERTM_INFO *p_ertm_info);
97 BOOLEAN (*ErtmConnectRsp)(BD_ADDR p_bd_addr, UINT8 id, UINT16 lcid,
98 UINT16 result, UINT16 status,
99 tL2CAP_ERTM_INFO *p_ertm_info);
100 BOOLEAN (*ConfigReq)(UINT16 cid, tL2CAP_CFG_INFO *p_cfg);
101 BOOLEAN (*ConfigRsp)(UINT16 cid, tL2CAP_CFG_INFO *p_cfg);
102 BOOLEAN (*DisconnectReq)(UINT16 cid);
103 BOOLEAN (*DisconnectRsp)(UINT16 cid);
104 UINT8 (*DataWrite)(UINT16 cid, char *p_data, UINT32 len);
105 BOOLEAN (*Ping)(BD_ADDR p_bd_addr, tL2CA_ECHO_RSP_CB *p_cb);
106 BOOLEAN (*Echo)(BD_ADDR p_bd_addr, BT_HDR *p_data, tL2CA_ECHO_DATA_CB *p_callback);
107 BOOLEAN (*SetIdleTimeout)(UINT16 cid, UINT16 timeout, BOOLEAN is_global);
108 BOOLEAN (*SetIdleTimeoutByBdAddr)(BD_ADDR bd_addr, UINT16 timeout);
109 UINT8 (*SetDesireRole)(UINT8 new_role);
110 void (*SetSecConnOnlyMode)(BOOLEAN secvalue);
111 UINT16 (*LocalLoopbackReq)(UINT16 psm, UINT16 handle, BD_ADDR p_bd_addr);
112 UINT16 (*FlushChannel)(UINT16 lcid, UINT16 num_to_flush);
113 BOOLEAN (*SetAclPriority)(BD_ADDR bd_addr, UINT8 priority);
114 BOOLEAN (*FlowControl)(UINT16 cid, BOOLEAN data_enabled);
115 BOOLEAN (*SendTestSFrame)(UINT16 cid, BOOLEAN rr_or_rej, UINT8 back_track);
116 BOOLEAN (*SetTxPriority)(UINT16 cid, tL2CAP_CHNL_PRIORITY priority);
117 BOOLEAN (*RegForNoCPEvt)(tL2CA_NOCP_CB *p_cb, BD_ADDR p_bda);
118 BOOLEAN (*SetChnlDataRate)(UINT16 cid, tL2CAP_CHNL_DATA_RATE tx, tL2CAP_CHNL_DATA_RATE rx);
119 BOOLEAN (*SetFlushTimeout)(BD_ADDR bd_addr, UINT16 flush_tout);
120 UINT8 (*DataWriteEx)(UINT16 cid, BT_HDR *p_data, UINT16 flags);
121 BOOLEAN (*SetChnlFlushability)(UINT16 cid, BOOLEAN is_flushable);
122 BOOLEAN (*GetPeerFeatures)(BD_ADDR bd_addr, UINT32 *p_ext_feat, UINT8 *p_chnl_mask);
123 BOOLEAN (*GetBDAddrbyHandle)(UINT16 handle, BD_ADDR bd_addr);
124 UINT8 (*GetChnlFcrMode)(UINT16 lcid);
125 UINT16 (*SendFixedChnlData)(UINT16 fixed_cid, BD_ADDR rem_bda, BT_HDR *p_buf);
126 void (*Cleanup)(void);
Srinu Jella0d7fbab2014-12-24 16:02:52 +0530127 bt_status_t (*RegisterLePsm) (UINT16 le_psm, BOOLEAN ConnType, UINT16 SecLevel,
128 UINT8 enc_key_size);
129 bt_status_t (*LeDeregister)(UINT16 psm);
130 UINT16 (*LeConnect) (UINT16 le_psm , BD_ADDR address, tL2CAP_LE_CFG_INFO *p_cfg);
131 BOOLEAN (*LeConnectRsp) (BD_ADDR p_bd_addr, UINT8 id, UINT16 lcid, UINT16 result,
132 UINT16 status, tL2CAP_LE_CFG_INFO *p_cfg);
133 BOOLEAN (*LeFlowControl) (UINT16 lcid, UINT16 credits);
134 void (*LeFreeBuf)(BT_HDR *p_buf);
Matadeen Mishra72153522016-05-11 21:16:09 -0700135} btl2cap_interface_t;
136
137typedef struct
138{
139 size_t size;
140 void (*Init)(void);
141 tMCA_HANDLE (*Register)(tMCA_REG *p_reg, tMCA_CTRL_CBACK *p_cback);
142 void (*Deregister)(tMCA_HANDLE handle);
143 tMCA_RESULT (*CreateDep)(tMCA_HANDLE handle, tMCA_DEP *p_dep, tMCA_CS *p_cs);
144 tMCA_RESULT (*DeleteDep)(tMCA_HANDLE handle, tMCA_DEP dep);
145 tMCA_RESULT (*ConnectReq)(tMCA_HANDLE handle, BD_ADDR bd_addr,
146 UINT16 ctrl_psm,
147 UINT16 sec_mask);
148 tMCA_RESULT (*DisconnectReq)(tMCA_CL mcl);
149 tMCA_RESULT (*CreateMdl)(tMCA_CL mcl, tMCA_DEP dep, UINT16 data_psm,
150 UINT16 mdl_id, UINT8 peer_dep_id,
151 UINT8 cfg, const tMCA_CHNL_CFG *p_chnl_cfg);
152 tMCA_RESULT (*CreateMdlRsp)(tMCA_CL mcl, tMCA_DEP dep,
153 UINT16 mdl_id, UINT8 cfg, UINT8 rsp_code,
154 const tMCA_CHNL_CFG *p_chnl_cfg);
155 tMCA_RESULT (*CloseReq)(tMCA_DL mdl);
156 tMCA_RESULT (*ReconnectMdl)(tMCA_CL mcl, tMCA_DEP dep, UINT16 data_psm,
157 UINT16 mdl_id, const tMCA_CHNL_CFG *p_chnl_cfg);
158 tMCA_RESULT (*ReconnectMdlRsp)(tMCA_CL mcl, tMCA_DEP dep,
159 UINT16 mdl_id, UINT8 rsp_code,
160 const tMCA_CHNL_CFG *p_chnl_cfg);
161 tMCA_RESULT (*DataChnlCfg)(tMCA_CL mcl, const tMCA_CHNL_CFG *p_chnl_cfg);
162 tMCA_RESULT (*Abort)(tMCA_CL mcl);
163 tMCA_RESULT (*Delete)(tMCA_CL mcl, UINT16 mdl_id);
164 tMCA_RESULT (*WriteReq)(tMCA_DL mdl, BT_HDR *p_pkt);
165 UINT16 (*GetL2CapChannel) (tMCA_DL mdl);
166}btmcap_interface_t;
167
Satish kumar sugasi2a86d962015-04-10 12:46:02 -0700168typedef struct
169{
170 size_t size;
171 //GATT common APIs (Both client and server)
172 tGATT_IF (*Register) (tBT_UUID *p_app_uuid128, tGATT_CBACK *p_cb_info);
173 void (*Deregister) (tGATT_IF gatt_if);
174 void (*StartIf) (tGATT_IF gatt_if);
175 BOOLEAN (*Connect) (tGATT_IF gatt_if, BD_ADDR bd_addr, BOOLEAN is_direct,tBT_TRANSPORT transport);
176 tGATT_STATUS (*Disconnect) (UINT16 conn_id);
177 BOOLEAN (*Listen) (tGATT_IF gatt_if, BOOLEAN start, BD_ADDR_PTR bd_addr);
178
179 //GATT Client APIs
180 tGATT_STATUS (*cConfigureMTU) (UINT16 conn_id, UINT16 mtu);
181 tGATT_STATUS (*cDiscover) (UINT16 conn_id, tGATT_DISC_TYPE disc_type, tGATT_DISC_PARAM *p_param );
182 tGATT_STATUS (*cRead) (UINT16 conn_id, tGATT_READ_TYPE type, tGATT_READ_PARAM *p_read);
183 tGATT_STATUS (*cWrite) (UINT16 conn_id, tGATT_WRITE_TYPE type, tGATT_VALUE *p_write);
184 tGATT_STATUS (*cExecuteWrite) (UINT16 conn_id, BOOLEAN is_execute);
185 tGATT_STATUS (*cSendHandleValueConfirm) (UINT16 conn_id, UINT16 handle);
186 void (*cSetIdleTimeout)(BD_ADDR bd_addr, UINT16 idle_tout);
Satish kumar sugasi292e3332015-06-19 17:35:49 -0700187 void (*cSetVisibility) (UINT16 disc_mode, UINT16 conn_mode);
Satish kumar sugasi2a86d962015-04-10 12:46:02 -0700188
189 //GATT Server APIs
190 //TODO - Add api on the need basis
191
192}btgatt_test_interface_t;
193
194typedef struct
195{
196 size_t size;
197 void (*init)(void);
198 BOOLEAN (*Register) (tSMP_CALLBACK *p_cback);
199 tSMP_STATUS (*Pair) (BD_ADDR bd_addr);
200 BOOLEAN (*PairCancel) (BD_ADDR bd_addr);
201 void (*SecurityGrant)(BD_ADDR bd_addr, UINT8 res);
202 void (*PasskeyReply) (BD_ADDR bd_addr, UINT8 res, UINT32 passkey);
203 BOOLEAN (*Encrypt) (UINT8 *key, UINT8 key_len, UINT8 *plain_text, UINT8 pt_len, tSMP_ENC *p_out);
204}btsmp_interface_t;
205typedef struct
206{
207 size_t size;
208 void (*Gap_AttrInit)();
209 void (*Gap_BleAttrDBUpdate)(BD_ADDR bd_addr, UINT16 int_min, UINT16 int_max, UINT16 latency, UINT16 sp_tout);
210}btgap_interface_t;
211
Matadeen Mishra72153522016-05-11 21:16:09 -0700212/** Bluetooth RFC tool commands */
213typedef enum {
214 RFC_TEST_CLIENT =1,
215 RFC_TEST_FRAME_ERROR,
216 RFC_TEST_ROLE_SWITCH,
217 RFC_TEST_SERVER,
218 RFC_TEST_DISCON,
219 RFC_TEST_CLIENT_TEST_MSC_DATA, //For PTS test case BV 21 and 22
220 RFC_TEST_WRITE_DATA
221}rfc_test_cmd_t;
222
223
224typedef struct {
225 bt_bdaddr_t bdadd;
226 uint8_t scn; //Server Channel Number
227}bt_rfc_conn_t;
228
229typedef struct {
230 bt_bdaddr_t bdadd;
231 uint8_t role; //0x01 for master
232}bt_role_sw;
233
234typedef union {
235 bt_rfc_conn_t conn;
236 uint8_t server;
237 bt_role_sw role_switch;
238}tRfcomm_test;
239
240typedef struct {
241 rfc_test_cmd_t param;
242 tRfcomm_test data;
243}tRFC;
244
245typedef struct {
246 size_t size;
247 bt_status_t (*init)( tL2CAP_APPL_INFO* callbacks );
248 void (*rdut_rfcomm)( UINT8 server );
249 void (*rdut_rfcomm_test_interface)( tRFC *input);
250 bt_status_t (*connect)( bt_bdaddr_t *bd_addr );
251 void (*cleanup)( void );
252} btrfcomm_interface_t;
253
254#endif
255
256__END_DECLS
257
258#endif /* ANDROID_INCLUDE_BT_TESTAPP_H */