@@ -68,175 +68,175 @@ static const struct bt_conn_auth_cb auth_callbacks;
68
68
#endif
69
69
70
70
static service_t ble_service = {
71
- .service_id = BLE_SERVICE_ID ,
72
- .client_connected = ble_client_connected ,
73
- .client_disconnected = ble_client_disconnected ,
71
+ .service_id = BLE_SERVICE_ID ,
72
+ .client_connected = ble_client_connected ,
73
+ .client_disconnected = ble_client_disconnected ,
74
74
};
75
75
76
76
static void ble_is_not_enabled_rsp (struct cfw_message * msg , int status )
77
77
{
78
- struct ble_enable_rsp * resp =
79
- (struct ble_enable_rsp * )cfw_alloc_rsp_msg (msg ,
80
- /* translate msg from req to rsp */
81
- (CFW_MESSAGE_ID (msg ) ^ MSG_ID_BLE_SERVICE_BASE )
82
- | MSG_ID_BLE_SERVICE_RSP ,
83
- sizeof (* resp ));
84
- resp -> status = status ;
85
- cfw_send_message (resp );
78
+ struct ble_enable_rsp * resp =
79
+ (struct ble_enable_rsp * )cfw_alloc_rsp_msg (msg ,
80
+ /* translate msg from req to rsp */
81
+ (CFW_MESSAGE_ID (msg ) ^ MSG_ID_BLE_SERVICE_BASE )
82
+ | MSG_ID_BLE_SERVICE_RSP ,
83
+ sizeof (* resp ));
84
+ resp -> status = status ;
85
+ cfw_send_message (resp );
86
86
}
87
87
88
88
#ifdef CONFIG_TCMD_BLE_DEBUG
89
89
static void handle_msg_id_ble_dbg (struct cfw_message * msg )
90
90
{
91
- struct nble_dbg_req params ;
92
- struct ble_dbg_req_rsp * resp = (void * )
93
- cfw_alloc_rsp_msg (msg , MSG_ID_BLE_DBG_RSP , sizeof (* resp ));
94
- struct ble_dbg_req_rsp * req = (struct ble_dbg_req_rsp * ) msg ;
91
+ struct nble_dbg_req params ;
92
+ struct ble_dbg_req_rsp * resp = (void * )
93
+ cfw_alloc_rsp_msg (msg , MSG_ID_BLE_DBG_RSP , sizeof (* resp ));
94
+ struct ble_dbg_req_rsp * req = (struct ble_dbg_req_rsp * ) msg ;
95
95
96
- params .u0 = req -> u0 ;
97
- params .u1 = req -> u1 ;
96
+ params .u0 = req -> u0 ;
97
+ params .u1 = req -> u1 ;
98
98
params .user_data = (void * )resp ;
99
- nble_dbg_req (& params );
99
+ nble_dbg_req (& params );
100
100
}
101
101
#endif /* CONFIG_TCMD_BLE_DEBUG */
102
102
103
103
void on_nble_dbg_rsp (const struct nble_dbg_rsp * params )
104
104
{
105
105
#ifdef CONFIG_TCMD_BLE_DEBUG
106
- struct ble_dbg_req_rsp * resp = params -> user_data ;
107
- if (!resp )
108
- return ;
109
- resp -> u0 = params -> u0 ;
110
- resp -> u1 = params -> u1 ;
111
- cfw_send_message (resp );
106
+ struct ble_dbg_req_rsp * resp = params -> user_data ;
107
+ if (!resp )
108
+ return ;
109
+ resp -> u0 = params -> u0 ;
110
+ resp -> u1 = params -> u1 ;
111
+ cfw_send_message (resp );
112
112
#endif /* CONFIG_TCMD_BLE_DEBUG */
113
113
}
114
114
115
115
116
116
static void handle_msg_id_ble_rpc_callin (struct message * msg , void * priv )
117
117
{
118
- struct ble_rpc_callin * rpc = container_of (msg , struct ble_rpc_callin , msg );
119
- /* handle incoming message */
118
+ struct ble_rpc_callin * rpc = container_of (msg , struct ble_rpc_callin , msg );
119
+ /* handle incoming message */
120
120
//pr_debug(LOG_MODULE_BLE, "%s-%d", __FUNCTION__, __LINE__);
121
- rpc_deserialize (rpc -> p_data , rpc -> len );
122
- bfree (rpc -> p_data );
123
- message_free (msg );
121
+ rpc_deserialize (rpc -> p_data , rpc -> len );
122
+ bfree (rpc -> p_data );
123
+ message_free (msg );
124
124
//pr_debug(LOG_MODULE_BLE, "%s-%d", __FUNCTION__, __LINE__);
125
125
}
126
126
127
127
static void ble_set_bda_cb (int status ,
128
128
void * user_data ,
129
129
const bt_addr_le_t * bda )
130
130
{
131
- struct ble_enable_req * req = user_data ;
131
+ struct ble_enable_req * req = user_data ;
132
132
133
- if (!req )
134
- return ;
133
+ if (!req )
134
+ return ;
135
135
136
- struct ble_enable_rsp * resp = (void * )cfw_alloc_rsp_msg (& req -> header ,
136
+ struct ble_enable_rsp * resp = (void * )cfw_alloc_rsp_msg (& req -> header ,
137
137
MSG_ID_BLE_ENABLE_RSP ,
138
138
sizeof (* resp ));
139
- resp -> status = status ;
140
-
141
- if (status == 0 ) {
142
- resp -> enable = 1 ;
143
-
144
- //nble_read_bda_req(resp);
145
- } else {
146
- /* error case */
147
- resp -> enable = 0 ;
148
- cfw_send_message (resp );
149
- }
150
- bfree (req );
139
+ resp -> status = status ;
140
+
141
+ if (status == 0 ) {
142
+ resp -> enable = 1 ;
143
+
144
+ //nble_read_bda_req(resp);
145
+ } else {
146
+ /* error case */
147
+ resp -> enable = 0 ;
148
+ cfw_send_message (resp );
149
+ }
150
+ bfree (req );
151
151
}
152
152
153
153
static void handle_ble_enable (struct ble_enable_req * req ,
154
154
struct _ble_service_cb * p_cb )
155
155
{
156
- pr_info (LOG_MODULE_BLE , "ble_enable: state %d" , p_cb -> ble_state );
156
+ pr_info (LOG_MODULE_BLE , "ble_enable: state %d" , p_cb -> ble_state );
157
157
158
- p_cb -> ble_state = BLE_ST_ENABLED ;
158
+ p_cb -> ble_state = BLE_ST_ENABLED ;
159
159
160
- if (req -> bda_present ) {
161
- struct nble_set_bda_req params ;
160
+ if (req -> bda_present ) {
161
+ struct nble_set_bda_req params ;
162
162
163
- params .cb = ble_set_bda_cb ;
164
- params .user_data = req ;
165
- params .bda = req -> bda ;
163
+ params .cb = ble_set_bda_cb ;
164
+ params .user_data = req ;
165
+ params .bda = req -> bda ;
166
166
167
- nble_set_bda_req (& params );
168
- } else {
169
- ble_set_bda_cb (0 , req , NULL );
170
- }
167
+ nble_set_bda_req (& params );
168
+ } else {
169
+ ble_set_bda_cb (0 , req , NULL );
170
+ }
171
171
}
172
172
173
173
static void handle_ble_disable (struct ble_enable_req * req , struct _ble_service_cb * p_cb )
174
174
{
175
- struct ble_enable_rsp * resp ;
175
+ struct ble_enable_rsp * resp ;
176
176
177
- pr_debug (LOG_MODULE_BLE , "ble_disable" );
178
- p_cb -> ble_state = BLE_ST_DISABLED ;
177
+ pr_debug (LOG_MODULE_BLE , "ble_disable" );
178
+ p_cb -> ble_state = BLE_ST_DISABLED ;
179
179
180
- bt_le_adv_stop ();
180
+ bt_le_adv_stop ();
181
181
182
- resp = (void * )cfw_alloc_rsp_msg (& req -> header ,
183
- MSG_ID_BLE_ENABLE_RSP ,
184
- sizeof (* resp ));
185
- cfw_send_message (resp ); // Sid. KW warning ack.
182
+ resp = (void * )cfw_alloc_rsp_msg (& req -> header ,
183
+ MSG_ID_BLE_ENABLE_RSP ,
184
+ sizeof (* resp ));
185
+ cfw_send_message (resp ); // Sid. KW warning ack.
186
186
187
187
}
188
188
189
189
static void ble_service_message_handler (struct cfw_message * msg , void * param )
190
190
{
191
- bool free_msg = true;
192
- struct _ble_service_cb * p_cb = param ;
193
- uint16_t msg_id = CFW_MESSAGE_ID (msg );
194
-
195
- if (p_cb -> ble_state < BLE_ST_ENABLED &&
196
- msg_id != MSG_ID_BLE_ENABLE_REQ ) {
197
- ble_is_not_enabled_rsp (msg , - ENODEV );
198
- goto out ;
199
- }
200
-
201
- switch (msg_id ) {
202
- case MSG_ID_BLE_ENABLE_REQ : {
203
- struct ble_enable_req * req =
204
- container_of (msg , struct ble_enable_req , header );
205
- if (p_cb -> ble_state ) {
206
- if (req -> enable ) {
207
- handle_ble_enable (req , p_cb );
208
- free_msg = false;
209
- } else
210
- handle_ble_disable (req , p_cb );
211
- } else {
212
- pr_debug (LOG_MODULE_BLE , "ble_hdl_msg: core service not opened!" );
213
- /* core service is not yet up */
214
- struct ble_enable_rsp * resp = (void * )cfw_alloc_rsp_msg (msg ,
215
- MSG_ID_BLE_ENABLE_RSP , sizeof (* resp ));
216
- resp -> status = - EINPROGRESS ;
217
- resp -> enable = 0 ;
218
- cfw_send_message (resp ); // Sid. KW warning ack.
219
- }
220
- }
221
- break ;
191
+ bool free_msg = true;
192
+ struct _ble_service_cb * p_cb = param ;
193
+ uint16_t msg_id = CFW_MESSAGE_ID (msg );
194
+
195
+ if (p_cb -> ble_state < BLE_ST_ENABLED &&
196
+ msg_id != MSG_ID_BLE_ENABLE_REQ ) {
197
+ ble_is_not_enabled_rsp (msg , - ENODEV );
198
+ goto out ;
199
+ }
200
+
201
+ switch (msg_id ) {
202
+ case MSG_ID_BLE_ENABLE_REQ : {
203
+ struct ble_enable_req * req =
204
+ container_of (msg , struct ble_enable_req , header );
205
+ if (p_cb -> ble_state ) {
206
+ if (req -> enable ) {
207
+ handle_ble_enable (req , p_cb );
208
+ free_msg = false;
209
+ } else
210
+ handle_ble_disable (req , p_cb );
211
+ } else {
212
+ pr_debug (LOG_MODULE_BLE , "ble_hdl_msg: core service not opened!" );
213
+ /* core service is not yet up */
214
+ struct ble_enable_rsp * resp = (void * )cfw_alloc_rsp_msg (msg ,
215
+ MSG_ID_BLE_ENABLE_RSP , sizeof (* resp ));
216
+ resp -> status = - EINPROGRESS ;
217
+ resp -> enable = 0 ;
218
+ cfw_send_message (resp ); // Sid. KW warning ack.
219
+ }
220
+ }
221
+ break ;
222
222
#ifdef CONFIG_TCMD_BLE_DEBUG
223
- case MSG_ID_BLE_DBG_REQ :
224
- handle_msg_id_ble_dbg (msg );
225
- break ;
223
+ case MSG_ID_BLE_DBG_REQ :
224
+ handle_msg_id_ble_dbg (msg );
225
+ break ;
226
226
#endif
227
- default :
228
- pr_warning (LOG_MODULE_BLE , "unsupported %d" , msg_id );
229
- break ;
230
- }
227
+ default :
228
+ pr_warning (LOG_MODULE_BLE , "unsupported %d" , msg_id );
229
+ break ;
230
+ }
231
231
out :
232
- if (free_msg )
233
- cfw_msg_free (msg );
232
+ if (free_msg )
233
+ cfw_msg_free (msg );
234
234
}
235
235
236
236
static void ble_client_connected (conn_handle_t * instance )
237
237
{
238
- if (_ble_cb .ble_state == BLE_ST_NOT_READY )
239
- pr_warning (LOG_MODULE_BLE , "BLE_CORE service is not registered" );
238
+ if (_ble_cb .ble_state == BLE_ST_NOT_READY )
239
+ pr_warning (LOG_MODULE_BLE , "BLE_CORE service is not registered" );
240
240
}
241
241
242
242
static void ble_client_disconnected (conn_handle_t * instance )
@@ -246,26 +246,30 @@ static void ble_client_disconnected(conn_handle_t *instance)
246
246
void ble_bt_rdy (int err )
247
247
{
248
248
BT_SERVICE_ASSERT (err == 0 );
249
- _ble_cb .ble_state = BLE_ST_DISABLED ;
249
+ _ble_cb .ble_state = BLE_ST_DISABLED ;
250
250
ble_inited = true;
251
251
252
- /* register BLE service */
253
- if (cfw_register_service (_ble_cb .queue ,
252
+ /* register BLE service */
253
+ if (cfw_register_service (_ble_cb .queue ,
254
254
& ble_service ,
255
255
ble_service_message_handler ,
256
256
& _ble_cb ) == -1 ) {
257
- panic (0xb1eb1e );
258
- }
257
+ panic (0xb1eb1e );
258
+ }
259
259
}
260
260
261
261
void ble_cfw_service_init (int service_id , T_QUEUE queue )
262
262
{
263
- uint32_t time_stamp_last = 0 ;
264
- _ble_cb .queue = queue ;
265
- _ble_cb . ble_state = BLE_ST_NOT_READY ;
263
+ _ble_cb . queue = queue ;
264
+ _ble_cb .ble_state = BLE_ST_NOT_READY ;
265
+ }
266
266
267
+ void ble_enable ()
268
+ {
269
+ uint32_t time_stamp_last = 0 ;
270
+
267
271
#ifdef CONFIG_IPC_UART_NS16550
268
- nble_driver_configure (queue , handle_msg_id_ble_rpc_callin );
272
+ nble_driver_configure (_ble_cb . queue , handle_msg_id_ble_rpc_callin );
269
273
#endif
270
274
271
275
ble_inited = false;
0 commit comments