@@ -204,118 +204,113 @@ trble_result_e rtw_ble_client_set_scan(uint16_t scan_interval, uint16_t scan_win
204204}
205205
206206trble_result_e rtw_ble_client_start_scan_with_filter (trble_scan_filter * scan_parm , bool whitelist_enable )
207- {
208- if (client_init_parm == NULL || client_init_parm -> trble_device_scanned_cb == NULL || scan_parm == NULL )
209- {
210- return TRBLE_FAIL ;
211- }
207+ {
208+ if (client_init_parm == NULL || client_init_parm -> trble_device_scanned_cb == NULL || scan_parm == NULL ) {
209+ return TRBLE_FAIL ;
210+ }
212211
213- rtk_bt_le_gap_dev_state_t new_state ;
214- if (RTK_BT_OK != rtk_bt_le_gap_get_dev_state (& new_state ))
215- {
216- dbg ("get dev state fail \n" );
217- }
212+ rtk_bt_le_gap_dev_state_t new_state ;
213+ if (RTK_BT_OK != rtk_bt_le_gap_get_dev_state (& new_state )) {
214+ dbg ("Get dev state fail \n" );
215+ }
218216
219217 if (new_state .gap_scan_state != GAP_SCAN_STATE_IDLE ) {
220218 dbg ("Scan already started!! \n" );
221219 return TRBLE_INVALID_STATE ;
222220 }
223221 rtk_bt_le_scan_info_filter_param_t scan_info ;
224- if (scan_parm -> raw_data_length != 0 ) {
222+ if (scan_parm -> raw_data_length != 0 ) {
225223 scan_info .len = scan_parm -> raw_data_length ;
226224 scan_info .enable = true;
227225 scan_info .p_filter = scan_parm -> raw_data ;
228226 scan_info .offset = 0 ;
229- if (RTK_BT_OK != rtk_bt_le_gap_scan_info_filter (& scan_info ))
230- {
231- dbg ("set scan info fail !! \n" );
232- return TRBLE_FAIL ;
233- } else {
234- dbg ("set scan info success \n" );
235- }
236- } else {
237- scan_info .enable = false;
227+ if (RTK_BT_OK != rtk_bt_le_gap_scan_info_filter (& scan_info )) {
228+ dbg ("Scan set info fail !! \n" );
229+ return TRBLE_FAIL ;
230+ } else {
231+ dbg ("Scan set info success \n" );
232+ }
233+ } else {
234+ scan_info .enable = false;
238235 scan_info .len = 0 ;
239236 scan_info .p_filter = NULL ;
240237 scan_info .offset = 0 ;
241- if (RTK_BT_OK == rtk_bt_le_gap_scan_info_filter (& scan_info ))
242- {
243- dbg ("disable scan info filter success \n" );
244- } else {
245- dbg ("disable scan info filter fail!!! \n" );
246- }
247- }
238+ if (RTK_BT_OK == rtk_bt_le_gap_scan_info_filter (& scan_info )) {
239+ dbg ("Disable scan info filter success \n" );
240+ } else {
241+ dbg ("Disable scan info filter fail!!! \n" );
242+ }
243+ }
248244
249- if (whitelist_enable ){
245+ if (whitelist_enable ) {
250246 rtk_bt_le_scan_param_t gap_scan_param ;
251247 gap_scan_param .type = RTK_BT_LE_SCAN_TYPE_ACTIVE ;
252248 gap_scan_param .interval = 0x60 ;
253249 gap_scan_param .window = 0x30 ;
254250 gap_scan_param .own_addr_type = RTK_BT_LE_ADDR_TYPE_PUBLIC ;
255251 gap_scan_param .filter_policy = RTK_BT_LE_SCAN_FILTER_ALLOW_ONLY_WLST ;
256252 gap_scan_param .duplicate_opt = RTK_BT_LE_SCAN_DUPLICATE_DISABLE ;
257- if (RTK_BT_OK != rtk_bt_le_gap_set_scan_param (& gap_scan_param ))
258- {
259- dbg ("set scan param fail \n" );
260- }
253+ if (RTK_BT_OK != rtk_bt_le_gap_set_scan_param (& gap_scan_param )) {
254+ dbg ("Set scan param fail \n" );
255+ }
256+ }
257+ if (RTK_BT_OK != rtk_bt_le_gap_start_scan ()) {
258+ dbg ("Start scan failed! \n" );
259+ return TRBLE_FAIL ;
261260 }
262- if (RTK_BT_OK != rtk_bt_le_gap_start_scan ())
263- {
264- dbg ("start scan failed! \n" );
265- return TRBLE_FAIL ;
266- }
267261
268- if (scan_parm -> scan_duration != 0 )
269- {
270- if (NULL == scan_filter_tmr_handle )
271- {
272- if (!osif_timer_create (& scan_filter_tmr_handle , "scan_with_filter" , 0 , scan_parm -> scan_duration , 0 , scan_stop_cb ))
273- {
274- dbg ("timer creat fail!! \n" );
275- return TRBLE_FAIL ;
276- } else {
277- dbg ("timer creat success \n" );
278- }
279-
280- if (!osif_timer_start (& scan_filter_tmr_handle ))
281- {
282- dbg ("timer start fail!! \n" );
283- return TRBLE_FAIL ;
284- } else {
285- dbg ("timer start success \n" );
286- }
287- } else {
288- if (!osif_timer_restart (& scan_filter_tmr_handle , scan_parm -> scan_duration ))
289- {
290- dbg ("timer restart fail!! \n" );
291- return TRBLE_FAIL ;
292- } else {
293- dbg ("timer restart success \n" );
294- }
295- }
296- }
297- return TRBLE_SUCCESS ;
262+ if (scan_parm -> scan_duration != 0 ) {
263+ if (NULL == scan_filter_tmr_handle ) {
264+ if (!osif_timer_create (& scan_filter_tmr_handle , "scan_with_filter" , 0 , scan_parm -> scan_duration , 0 , scan_stop_cb )) {
265+ dbg ("Scan timer creat fail!! \n" );
266+ return TRBLE_FAIL ;
267+ }
268+
269+ if (!osif_timer_start (& scan_filter_tmr_handle )) {
270+ dbg ("Scan timer start fail!! \n" );
271+ return TRBLE_FAIL ;
272+ }
273+ } else {
274+ if (!osif_timer_restart (& scan_filter_tmr_handle , scan_parm -> scan_duration )) {
275+ dbg ("Scan timer restart fail!! \n" );
276+ return TRBLE_FAIL ;
277+ }
278+ }
279+ dbg ("Scan timer start success \n" );
280+ }
281+ return TRBLE_SUCCESS ;
298282}
299283
300284trble_result_e rtw_ble_client_stop_scan (void )
301- {
302- rtk_bt_le_gap_dev_state_t new_state ;
303- if (RTK_BT_OK != rtk_bt_le_gap_get_dev_state (& new_state ))
304- {
305- dbg ("get dev state fail \n" );
306- }
285+ {
286+ rtk_bt_le_gap_dev_state_t new_state ;
287+ if (RTK_BT_OK != rtk_bt_le_gap_get_dev_state (& new_state )) {
288+ dbg ("Get dev state fail \n" );
289+ }
307290
308291 if (new_state .gap_scan_state != GAP_SCAN_STATE_SCANNING ) {
309292 return TRBLE_INVALID_STATE ;
310293 }
311294
312- if (RTK_BT_OK != rtk_bt_le_gap_stop_scan ())
313- {
314- dbg ("stop scan failed! \n" );
315- return TRBLE_FAIL ;
316- }
295+ if (RTK_BT_OK != rtk_bt_le_gap_stop_scan ()) {
296+ dbg ("Stop scan failed! \n" );
297+ return TRBLE_FAIL ;
298+ }
299+ if (!osif_timer_stop (& scan_filter_tmr_handle )) {
300+ dbg ("Scan timer stop fail!! \n" );
301+ }
302+ return TRBLE_SUCCESS ;
303+ }
317304
318- return TRBLE_SUCCESS ;
305+ trble_result_e rtw_ble_client_delete_scan_timer (void )
306+ {
307+ if (scan_filter_tmr_handle ) {
308+ if (!osif_timer_delete (& scan_filter_tmr_handle )) {
309+ dbg ("Scan timer delete fail!! \n" );
310+ return TRBLE_FAIL ;
311+ }
312+ }
313+ return TRBLE_SUCCESS ;
319314}
320315
321316trble_result_e rtw_ble_client_connect (trble_conn_info * conn_info , bool is_secured_connect )
@@ -847,14 +842,16 @@ trble_result_e rtw_ble_client_operation_enable_notification_and_indication(trble
847842
848843trble_result_e rtw_ble_client_deinit (void )
849844{
850- ble_tizenrt_central_main (0 );
845+ ble_tizenrt_central_main (0 );
851846
852- osif_mem_free (client_init_parm );
853- client_init_parm = NULL ;
854- osif_mem_free (ble_tizenrt_conn_ind );
847+ rtw_ble_client_delete_scan_timer ();
848+
849+ osif_mem_free (client_init_parm );
850+ client_init_parm = NULL ;
851+ osif_mem_free (ble_tizenrt_conn_ind );
855852 ble_tizenrt_conn_ind = NULL ;
856853
857- return TRBLE_SUCCESS ;
854+ return TRBLE_SUCCESS ;
858855}
859856
860857#endif /* TRBLE_CLIENT_C_ */
0 commit comments