• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /******************************************************************************
2  * Copyright (c) 2022 Telink Semiconductor (Shanghai) Co., Ltd. ("TELINK")
3  * All rights reserved.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *     http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  *****************************************************************************/
18 #ifndef SIMPLE_SDP_H_
19 #define SIMPLE_SDP_H_
20 
21 #include "device_manage.h"
22 #include "tl_common.h"
23 #include "vendor/common/user_config.h"
24 
25 #ifndef BLE_MASTER_SIMPLE_SDP_ENABLE
26 #define BLE_MASTER_SIMPLE_SDP_ENABLE 0
27 #endif
28 
29 #if (BLE_MASTER_SIMPLE_SDP_ENABLE)
30 
31 typedef void (*main_service_t)(void);
32 extern main_service_t main_service;
33 
34 extern int master_sdp_pending;
35 extern dev_char_info_t cur_sdp_device;
36 
37 #define ATT_DB_UUID16_NUM  20
38 #define ATT_DB_UUID128_NUM 8
39 
40 typedef struct {
41     u8 num;
42     u8 property;
43     u16 handle;
44     u16 uuid;
45     u16 ref;
46 } att_db_uuid16_t;  // 8-byte
47 
48 typedef struct {
49     u8 num;
50     u8 property;
51     u16 handle;
52     u8 uuid[16];
53 } att_db_uuid128_t;  // 20-byte
54 
55 typedef struct {
56     u8 type;
57     u8 rf_len;
58     u16 l2capLen;
59     u16 chanId;
60     u8 opcode;
61     u8 datalen;
62     u8 data[1];  // character_handle / property / value_handle / value
63 } ble_att_readByTypeRsp_t;
64 
65 typedef struct {
66     u8 type;
67     u8 rf_len;
68     u16 l2capLen;
69     u16 chanId;
70     u8 opcode;
71     u8 value[22];
72 } ble_att_readRsp_t;
73 
74 #define ATT_BOND_MARK  0x5A
75 #define ATT_ERASE_MARK 0x00
76 
77 typedef struct {
78     u8 flag;
79     u8 adr_type;
80     u8 addr[6];
81 
82     u8 rsvd[8];  // very important: 16 byte aligned, to avoid different flash page write for a sequence data
83 
84 #if (PEER_SLAVE_USE_RPA_EN)
85     u8 irk[16];  // if peer device mac_adress is RPA(resolvable private address), IRK will be used
86 #endif
87 
88     u16 char_handle[CHAR_HANDLE_MAX];
89 } dev_att_t;
90 
91 u16 blm_att_findHandleOfUuid16(att_db_uuid16_t *p, u16 uuid, u16 ref);
92 u16 blm_att_findHandleOfUuid128(att_db_uuid128_t *p, const u8 *uuid);
93 
94 /**
95  * @brief   SDP handler.
96  *          !!! Note: This is a simple SDP processing implemented by telink.
97  * @param   none.
98  * @return  none.
99  */
100 void app_service_discovery(void);
101 
102 /**
103  * @brief       This function is used to register SDP handler.
104  * @param[in]   p       - Pointer point to SDP handler.
105  * @return      none.
106  */
107 void app_register_service(void *p);
108 
109 /**
110  * @brief       This function is used to process ATT packets related to SDP
111  * @param[in]   connHandle  - connection handle
112  * @param[in]   p           - Pointer point to ATT data buffer.
113  * @return      no used
114  */
115 int host_att_client_handler(u16 connHandle, u8 *p);
116 
117 /**
118  * @brief       This function is used to register ble stack mainloop function.
119  * @param[in]   p           - Pointer point to ble stack mainloop function.
120  * @return
121  */
122 int host_att_register_idle_func(void *p);
123 
124 /**
125  * @brief     SDP loop
126  * @param[in]  none.
127  * @return     none.
128  */
129 void simple_sdp_loop(void);
130 
131 /**
132  * @brief       Used for add peer device service ATThandle.
133  * @param[in]   dev_char_info       - Pointer point to data buffer.
134  * @return      0: success
135  *              1: failed
136  */
137 int dev_char_info_add_peer_att_handle(dev_char_info_t *dev_char_info);
138 
139 /**
140  * @brief       Use for store peer device att handle to flash.
141  * @param[in]   dev_char_info    Pointer point to peer device ATT handle info.
142  * @return      0: failed
143  *             !0: return falsh address
144  */
145 int dev_char_info_store_peer_att_handle(dev_char_info_t *dev_char_info);
146 
147 /**
148  * @brief       Get peer device att handle info by peer address
149  * @param[in]   adr_type         address type
150  * @param[in]   addr             Pointer point to peer address buffer
151  * @param[out]  dev_att          Pointer point to dev_att_t
152  * @return      0: failed
153  *             !0: return falsh address
154  */
155 int dev_char_info_search_peer_att_handle_by_peer_mac(u8 adr_type, u8 *addr, dev_att_t *dev_att);
156 
157 /**
158  * @brief       Delete peer device att handle info by peer address
159  * @param[in]   adr_type         address type
160  * @param[in]   addr             Pointer point to peer address buffer
161  * @return      0: success
162  *              1: not find
163  */
164 int dev_char_info_delete_peer_att_handle_by_peer_mac(u8 addrType, u8 *addr);
165 
166 #endif
167 
168 #endif /* SIMPLE_SDP_H_ */
169