comparison src/aci2/mfw/mfw_bt_dm.c @ 3:93999a60b835

src/aci2, src/condat2: import of g23m/condat source pieces from TCS211
author Mychaela Falconia <falcon@freecalypso.org>
date Mon, 26 Sep 2016 00:29:36 +0000
parents
children
comparison
equal deleted inserted replaced
2:c41a534f33c6 3:93999a60b835
1 /*
2 +-------------------------------------------------------------------+
3 | PROJECT: MMI-Framework (8445) $Workfile:: mfw_bt_dm.c $|
4 | $Author:: NDH $Revision:: 1 $|
5 | CREATED: 22.04.04 $Modtime:: 22.04.04 11:07 $|
6 | STATE : code |
7 +-------------------------------------------------------------------+
8
9
10 MODULE : MFW_BT_DM
11
12 PURPOSE : This module contains the functions for MFW Bluetooth Device Manager Profile
13
14
15 */
16
17 #define ENTITY_MFW
18
19 #include <string.h>
20
21 #if defined (NEW_FRAME)
22
23 #include "typedefs.h"
24 #include "vsi.h"
25 #include "pei.h"
26 #include "custom.h"
27 #include "gsm.h"
28
29 #else
30
31 #include "STDDEFS.H"
32 #include "custom.h"
33 #include "gsm.h"
34 #include "vsi.h"
35
36 #endif
37
38 #include "bta_riviera.h"
39 #include "mfw_bte.h"
40 #include "mfw_bt_dm.h"
41 #include "mfw_bt_geh.h"
42 #include "mfw_bt_flash.h"
43
44
45 T_MFW_BT_CB mfw_bt_cb;
46
47 /* file where is stored bd address of the device to connect */
48 #ifndef MFW_BT_BD_ADDR_FILE
49 #define MFW_BT_BD_ADDR_FILE "/bt/remote_bd"
50 #endif
51
52 static T_MFW_BT_STATUS mfw_bt_dm_trust_device(BOOLEAN is_trusted, BD_ADDR bd_addr);
53
54
55 /*******************************************************************************
56
57 $Function: mfw_bt_dm_set_visibility
58
59 $Description: set visibility of local BT device
60
61 $Returns: T_MFW_BT_STATUS. Success or fail.
62
63 $Arguments: is_visible: new visibility setting. is_temp: define whether it is a temporary
64 modification ( TRUE ) or a permanent one ( FALSE ).
65
66 *******************************************************************************/
67 T_MFW_BT_STATUS mfw_bt_dm_set_visibility( BOOL is_visible, BOOL is_temp)
68 {
69 /* other devices will be able to find this device during an inquiry */
70 if( mfw_bt_cb.is_started == TRUE )
71 BTA_DmSetVisibility( (is_visible)?BTA_DM_GENERAL_DISC:BTA_DM_NON_DISC,
72 BTA_DM_CONN);
73
74 if( is_temp == TRUE)
75 /* it looks like this is only a temporary change => don't store that in flash! */
76 return MFW_BT_SUCCESS;
77
78 /* update to nvram and mfw_bt_cfg */
79 return mfw_bt_store_visibility( is_visible );
80 }
81
82 /*******************************************************************************
83
84 $Function: mfw_bt_dm_get_visibility
85
86 $Description: get visibility of local BT device
87
88 $Returns: TRUE if visible, FALSE if not.
89
90 $Arguments: none
91
92 *******************************************************************************/
93 BOOL mfw_bt_dm_get_visibility( void )
94 {
95 return mfw_bt_read_visibility( );
96 }
97
98
99
100 /*******************************************************************************
101
102 $Function: mfw_bt_dm_get_local_name
103
104 $Description: read local BT device name
105
106 $Returns: a pointer to a string. NULL if no name available. One should make a copy of
107 string if he wants to use it/modify it.
108
109 $Arguments: none
110
111 *******************************************************************************/
112 UINT8 * mfw_bt_dm_get_local_name( void )
113 {
114 return mfw_bt_read_local_name();
115 }
116
117
118
119
120 /*******************************************************************************
121
122 $Function: mfw_bt_dm_set_local_name
123
124 $Description: set local BT device name
125
126 $Returns: T_MFW_BT_STATUS
127
128 $Arguments: new name. Pointer to a string. This string is copied locally. Buffer is not freed.
129
130 *******************************************************************************/
131 T_MFW_BT_STATUS mfw_bt_dm_set_local_name( INT8 *name )
132 {
133 if( strlen((char*)name) == 0 )
134 {
135 /* BMI should never ever send back an empty string, except at start-up */
136 if( mfw_bt_cb.is_name_requested == FALSE )
137 return MFW_BT_FAIL;
138
139 /* we are here, this means:
140 - it's a start-up
141 - apparently, the local name was never set. => it's the first start-up
142 - the user don't really want to use BT as he cancelled the setting.
143 => this means we do want to stop BT... So go for it! :o) */
144 mfw_bt_disable( );
145 return MFW_BT_SUCCESS;
146 }
147
148 if( mfw_bt_cb.is_name_requested == TRUE )
149 mfw_bt_cb.is_name_requested = FALSE;
150
151 if( strlen((char*)name) > MFW_BT_NAME_LENGTH )
152 return MFW_BT_INVALID_DATA;
153
154 if( mfw_bt_cb.is_started )
155 BTA_DmSetDeviceName( (char*)name );
156 /* update to nv memory and mfw_bt_cfg with new name */
157 return mfw_bt_store_local_name( (char*) name );
158 }
159
160 /*******************************************************************************
161
162 $Function: mfw_bt_dm_get_bt_status
163
164 $Description: get the status of the local Bluetooth system. Used at start-up to decide whether
165 or not we want BT to be started by default.
166
167 $Returns: MFW_BT_SUCCESS is BT is started. 0 if OFF
168
169 $Arguments:
170
171 *******************************************************************************/
172 BOOL mfw_bt_dm_get_bt_status( void )
173 {
174 return mfw_bt_read_status( );
175
176 }
177
178
179
180
181
182 /*******************************************************************************
183
184 $Function: mfw_bt_dm_pin_code
185
186 $Description: used by BMI to send back a pin code
187
188 $Returns: T_MFW_BT_STATUS. MFW_BT_NOT_INITIALISED is BT is not started.
189
190 $Arguments: pin code and pin code length. This data is copied.
191
192 *******************************************************************************/
193 T_MFW_BT_STATUS mfw_bt_dm_pin_code(UINT8* pin_code, UINT8 pin_len)
194 {
195 BOOLEAN accept = TRUE;
196
197 if( mfw_bt_cb.is_started != TRUE )
198 return MFW_BT_NOT_INITIALISED;
199
200 if(pin_len == 0)
201 accept = FALSE;
202 BTA_DmPinReply( mfw_bt_cb.peer_bdaddr,
203 accept,
204 pin_len,
205 pin_code);
206
207 return MFW_BT_SUCCESS;
208 }
209
210
211
212 /*******************************************************************************
213
214 $Function: mfw_bt_dm_bond
215
216 $Description: used by BMI to send a pin code in order to establish a bonding with a
217 remote device.
218
219 $Returns: T_MFW_BT_STATUS. MFW_BT_NOT_INITIALISED is BT is not started.
220
221
222 $Arguments: BD_ADDR of the remote device, pin code and pin code length. Data is copied.
223
224 *******************************************************************************/
225 T_MFW_BT_STATUS mfw_bt_dm_bond(BD_ADDR bd_addr, UINT8* pin_code, UINT8 pin_len )
226 {
227 if( mfw_bt_cb.is_started != TRUE )
228 return MFW_BT_NOT_INITIALISED;
229
230
231 MFW_BT_TRACE("try to bond with stored device");
232 if(pin_len != 0)
233 {
234 /* now tell the BT stack */
235 BTA_DmBond ( bd_addr, pin_len, pin_code );
236 return MFW_BT_SUCCESS;
237 }
238 else
239 {
240 MFW_BT_TRACE(" [ mfw_bt dm bond]: no pin code entered!");
241 return MFW_BT_FAIL;
242 }
243
244 }
245
246
247 /*******************************************************************************
248
249 $Function: mfw_bt_dm_authorize_resp
250
251 $Description: used to answer to an authorization request
252
253 $Returns: T_MFW_BT_STATUS. SUCCESS/FAIL, but also:
254 MFW_BT_NOT_INITIALISED is BT is not started.
255 MFW_BT_INVALID_DATA if auth value is not correct.
256 MFW_BT_UNKNOWN_DEVICE if BD_addr is not recognized.
257 MFW_BT_DATA_BASE_FULL if there are already too many devices in the DB.
258
259
260 $Arguments: MFW_BT_AUTH_FAIL to refuse,
261 MFW_BT_AUTH_ONCE to grant access temporarily,
262 MFW_BT_AUTH_ALWAYS to grant permanent access
263
264 *******************************************************************************/
265 T_MFW_BT_STATUS mfw_bt_dm_authorize_resp( T_MFW_BT_AUTHORIZE auth)
266 {
267 T_MFW_BT_STATUS status;
268
269 if( mfw_bt_cb.is_started != TRUE )
270 return MFW_BT_NOT_INITIALISED;
271
272 switch (auth)
273 {
274 case MFW_BT_AUTH_FAIL:
275 /* reject */
276 BTA_DmAuthorizeReply( mfw_bt_cb.peer_bdaddr,
277 mfw_bt_cb.peer_service,
278 BTA_DM_NOT_AUTH);
279 mfw_bt_dm_trust_device( FALSE, mfw_bt_cb.peer_bdaddr );
280 break;
281
282 case MFW_BT_AUTH_ALWAYS:
283 /*
284 ** CQ22024 : Set the device as Trusted, and Authorise it for this an all subsequent connections
285 ** If writing to the Flash fails, proceed with the authorisation anyway.
286 */
287 status = mfw_bt_dm_trust_device( TRUE, mfw_bt_cb.peer_bdaddr );
288
289 /*
290 ** Even if we fail to write the information to the FLASH, we should continue with the
291 ** Authorisation procedure. If the device is unknown, the device will remain Authorised as
292 ** long as the Handset is not powered down (Not ideal, but better than refusing Authorisation all together)
293 */
294 BTA_DmAuthorizeReply( mfw_bt_cb.peer_bdaddr,
295 mfw_bt_cb.peer_service,
296 BTA_DM_AUTH_PERM);
297 break;
298
299 case MFW_BT_AUTH_ONCE:
300 /* CQ22024 : tell the BT stack we authorize the device, but for this connection only */
301 BTA_DmAuthorizeReply( mfw_bt_cb.peer_bdaddr,
302 mfw_bt_cb.peer_service,
303 BTA_DM_AUTH_TEMP);
304 break;
305
306 default:
307 return MFW_BT_INVALID_DATA;
308 }
309 return MFW_BT_SUCCESS;
310 }
311
312
313 /*******************************************************************************
314
315 $Function: mfw_bt_dm_sig_strength
316
317 $Description: ask for the link quality
318
319 $Returns: T_MFW_BT_STATUS. MFW_BT_NOT_INITIALISED if BT is not started.
320
321 $Arguments: T_MFW_BT_DM_SIG_STRENGTH sig_strength, UINT16 period, BOOLEAN is_on
322 See BTA documentation for more details.
323
324 *******************************************************************************/
325 T_MFW_BT_STATUS mfw_bt_dm_sig_strength ( T_MFW_BT_DM_SIG_STRENGTH sig_strength,
326 UINT16 period,
327 BOOLEAN is_on )
328 {
329 if( mfw_bt_cb.is_started != TRUE )
330 return MFW_BT_NOT_INITIALISED;
331 BTA_DmSignalStrength((tBTA_SIG_STRENGTH_MASK) sig_strength, period, is_on);
332 return MFW_BT_SUCCESS;
333 }
334
335
336 /*******************************************************************************
337
338 $Function: mfw_bt_dm_get_known_devices
339
340 $Description: used by BMI to get the list of known devices for a specified condition: either a
341 service mask, either a bd address ( union ).
342 MFW will fill in the variables: pp_device => table of known devices
343 number_of_devices => number of devices.
344 MFW will allocate memory for each device found. It's up to BMI to free it!
345
346 $Returns: T_MFW_BT_STATUS.
347 If BD_ADDR is specified, might return MFW_BT_UNKNOWN_DEVICE.
348 The answers will be returned using BMI signals:
349 - E_BT_DM_INQ_CMPL with the number of devices
350 - E_BT_DM_DISC_RES for each device
351 - then E_BT_DM_DISC_CMPL when it's done.
352
353 $Arguments: BD_ADDR if looking for a particular device. services if looking for a
354 category of device. If bd_addr is specified, ignore services. If services set
355 to 0, will return all the known devices.
356
357 *******************************************************************************/
358 void mfw_bt_dm_get_known_devices ( BD_ADDR bd_addr,
359 T_MFW_BT_SERVICE_MASK services)
360 {
361 T_MFW_BT_REM_DEVICE *ptr_db_device[MFW_BT_NUM_REM_DEVICE];
362 UINT8 i, number_of_devices;
363 T_MFW_BT_DM_INQ_CMPL inq_cmpl_res;
364 T_MFW_BT_STATUS status;
365 BD_ADDR null_bd_addr;
366
367 number_of_devices = 0;
368 memset(&null_bd_addr[0], 0x00, sizeof(BD_ADDR));
369
370 /* we have a BT address, try to find the related data */
371 /* CQ21834 : cannot treat bd_addr as a pointer, because it is passed by value. Use MemCmp */
372 if( memcmp(&bd_addr[0], &null_bd_addr[0], sizeof(BD_ADDR)) != 0 )
373 {
374 ptr_db_device[0] = mfw_bt_get_device_info(bd_addr);
375
376 if(ptr_db_device[0] != NULL)
377 {
378 if((ptr_db_device[0])->is_new == FALSE)
379 number_of_devices = 1;
380 }
381 }
382 else
383 {
384 /* Now we want to find all the devices which support the given services */
385 mfw_bt_get_device_by_service(services, &ptr_db_device[0], &number_of_devices );
386 }
387
388 /* first send the number of found devices. this is important! BMI shouldn't do anything
389 before he gets all the answer */
390 inq_cmpl_res.num_resps = number_of_devices;
391 mfw_bt_signal( E_BT_DM_INQ_CMPL, (void*)&inq_cmpl_res);
392
393 if (number_of_devices > 0)
394 {
395 /*
396 ** CQ21834 : The incorrect structure was being used for the signal, so the data was never received by the BMI.
397 */
398 T_MFW_BT_DM_DISC_RES disc_res;
399
400 /* now for each device found, send a signal to BMI. This will copy the data! */
401 for( i=0; i<number_of_devices; i++ )
402 {
403 memcpy((void *)&disc_res, (void *)ptr_db_device[i], sizeof(disc_res));
404
405 mfw_bt_signal( E_BT_DM_DISC_RES, (void *)&disc_res);
406 }
407
408 mfw_bt_signal( E_BT_DM_DISC_CMPL, NULL);
409 }
410
411 return;
412
413 }
414
415
416
417
418
419
420
421 /*******************************************************************************
422
423 $Function: mfw_bt_dm_trust_device
424
425 $Description: specify whether a remote device should or not be trusted ( => access granted )
426
427 $Returns: T_MFW_BT_STATUS
428 success, failure, MFW_BT_UNKNOWN_DEVICE
429
430 $Arguments: BOOLEAN for the permission; BD address of the remote device
431
432 *******************************************************************************/
433 T_MFW_BT_STATUS mfw_bt_dm_trust_device(BOOLEAN is_trusted, BD_ADDR bd_addr)
434 {
435 T_MFW_BT_REM_DEVICE * p_device;
436 T_MFW_BT_STATUS status;
437
438 /* check if we know this device*/
439 if(( p_device = mfw_bt_get_device_info(bd_addr)) == NULL )
440 /* unknown device... */
441 return MFW_BT_UNKNOWN_DEVICE;
442
443 p_device->is_trusted = is_trusted;
444 if (( status = mfw_bt_flash_store_device(p_device)) != MFW_BT_SUCCESS )
445 return status;
446
447 /* update BTA with new settings */
448 if( mfw_bt_cb.is_started )
449 {
450 if(p_device->link_key_present)
451 BTA_DmAddDevice(bd_addr, p_device->link_key, BTA_ALL_SERVICE_MASK, is_trusted);
452 else
453 BTA_DmAddDevice(bd_addr, NULL, BTA_ALL_SERVICE_MASK, is_trusted);
454 }
455
456 return MFW_BT_SUCCESS;
457 }
458
459
460
461 /*******************************************************************************
462
463 $Function: mfw_bt_dm_delete_device
464
465 $Description: remove a device from the local DB
466
467 $Returns: T_MFW_BT_STATUS ( MFW_BT_SUCCESS, MFW_BT_FAIL, MFW_BT_UNKNOWN_DEVICE )
468
469 $Arguments: BD address
470
471 *******************************************************************************/
472 T_MFW_BT_STATUS mfw_bt_dm_delete_device(BD_ADDR bd_addr)
473 {
474 if( mfw_bt_cb.is_started )
475 BTA_DmRemoveDevice (bd_addr);
476 return mfw_bt_flash_delete_device(bd_addr);
477 }
478
479
480
481 /*******************************************************************************
482
483 $Function: mfw_bt_dm_add_device
484
485 $Description: This will store permanently a device in Flash.
486
487 $Returns: T_MFW_BT_STATUS
488 errors: MFW_BT_UNKNOWN_DEVICE, MFW_BT_DATA_BASE_FULL,
489
490
491 $Arguments: new BD address
492
493 *******************************************************************************/
494 T_MFW_BT_STATUS mfw_bt_dm_add_device(BD_ADDR bd_addr)
495 {
496 T_MFW_BT_REM_DEVICE *p_device;
497 T_MFW_BT_STATUS status;
498
499 MFW_BT_TRACE("mfw_bt_dm_add_device()");
500
501 /* get the info about this device */
502 if( ( p_device = mfw_bt_get_device_info( bd_addr)) == NULL)
503 return MFW_BT_UNKNOWN_DEVICE;
504
505 if( p_device->is_new == TRUE )
506 {
507 /*
508 ** CQ21834 : Ensure that the is_new value is set before writing the data to Flash, so that it will be
509 ** set correctly when the handset is restarted.
510 */
511 p_device->is_new = FALSE;
512 if((status = mfw_bt_flash_store_device(p_device))!=MFW_BT_SUCCESS)
513 return status;
514 }
515
516 /* update BTA device database */
517 if( mfw_bt_cb.is_started )
518 {
519 if(p_device->link_key_present)
520 BTA_DmAddDevice(p_device->bd_addr, p_device->link_key,
521 p_device->trusted_services, p_device->is_trusted);
522 else
523 BTA_DmAddDevice(p_device->bd_addr, NULL,
524 p_device->trusted_services, p_device->is_trusted);
525 }
526 return MFW_BT_SUCCESS;
527
528 }
529
530
531
532 /*******************************************************************************
533
534 $Function: mfw_bt_dm_rename_device
535
536 $Description: modify the friendly name of a known ( already stored ) remote device
537
538 $Returns: T_MFW_BT_STATUS.
539 MFW_BT_UNKNOWN_DEVICE, DATA_BASE_FULL, MFW_BT_INVALID_DATA...
540
541 $Arguments: bd address of the remote device and the new name associated
542
543 *******************************************************************************/
544 T_MFW_BT_STATUS mfw_bt_dm_rename_device(BD_ADDR bd_addr, UINT8* new_name)
545 {
546 T_MFW_BT_REM_DEVICE *p_device;
547
548 if( ( p_device = mfw_bt_get_device_info( bd_addr)) == NULL )
549 return MFW_BT_UNKNOWN_DEVICE;
550 /* if this device is new ( == in the inq DB ), we don't want to do anything */
551 if( p_device->is_new == TRUE )
552 return MFW_BT_FAIL;
553 /* verify the string is OK */
554 if( strlen( (char*)new_name ) > MFW_BT_NAME_LENGTH )
555 return MFW_BT_INVALID_DATA;
556 strcpy(p_device->friendly_name, (char*)new_name );
557 return mfw_bt_flash_store_device(p_device);
558
559 }
560
561
562
563
564
565
566 /*
567 ** Functions used to interact with the BT "search engine"
568 */
569
570
571 /*******************************************************************************
572
573 $Function: mfw_bt_dm_discover_device
574
575 $Description: Discovers services on a device
576
577 $Returns: T_MFW_BT_STATUS. MFW_BT_NOT_INITIALISED if BT not started.
578
579 $Arguments: bd address of the remote device to discover
580
581 *******************************************************************************/
582 T_MFW_BT_STATUS mfw_bt_dm_discover_device(BD_ADDR bd_addr)
583 {
584
585 T_MFW_BT_SERVICE_MASK client_services;
586
587 if( mfw_bt_cb.is_started != TRUE )
588 return MFW_BT_NOT_INITIALISED;
589
590 /* remember it's an inquiry */
591 mfw_bt_cb.is_discovery = TRUE;
592
593 /* we need to find only services for which we can be in client role, plus HS/HF */
594 client_services = ((BTA_SUPPORTED_CLIENT_SERVICES & \
595 ~( BTA_DUN_SERVICE_MASK | BTA_FAX_SERVICE_MASK )) \
596 | BTA_HSP_SERVICE_MASK | BTA_HFP_SERVICE_MASK );
597
598 BTA_DmDiscover(bd_addr, BTA_ALL_SERVICE_MASK, (tBTA_DM_SEARCH_CBACK*)mfw_bt_dm_search_cb);
599
600 return MFW_BT_SUCCESS;
601 }
602
603
604 /*******************************************************************************
605
606 $Function: mfw_bt_dm_is_discover
607
608 $Description: Checks if we are in discovering services process
609
610 $Returns:
611
612 $Arguments: None
613
614 *******************************************************************************/
615 UINT8 mfw_bt_dm_is_discover(void)
616 {
617 return mfw_bt_cb.is_discovery;
618 }
619
620
621
622 /*******************************************************************************
623
624 $Function: mfw_bt_dm_cancel_search
625
626 $Description: cancel an ongoing search
627
628 $Returns: MFW_BT_NOT_INITIALISED if BT not started.
629
630 $Arguments:
631
632 *******************************************************************************/
633 T_MFW_BT_STATUS mfw_bt_dm_cancel_search( void )
634 {
635 if( mfw_bt_cb.is_started != TRUE )
636 return MFW_BT_NOT_INITIALISED;
637 BTA_DmSearchCancel();
638 return MFW_BT_SUCCESS;
639 }
640
641
642 /*******************************************************************************
643
644 $Function: mfw_bt_dm_search
645
646 $Description: Searches for devices supporting the services specified. If services = 0, will
647 return all the found devices regardless of their functionalities.
648
649 $Returns: MFW_BT_NOT_INITIALISED if BT not started.
650
651 $Arguments: services. If
652
653 *******************************************************************************/
654 T_MFW_BT_STATUS mfw_bt_dm_search(T_MFW_BT_SERVICE_MASK services)
655 {
656 tBTA_DM_INQ inq_params;
657 UINT8 inq_index;
658
659 if( mfw_bt_cb.is_started != TRUE )
660 return MFW_BT_NOT_INITIALISED;
661 mfw_bt_cb.is_discovery = FALSE;
662 inq_params.mode = 0;
663 inq_params.duration = MFW_BT_DEFAULT_INQ_DURATION;
664 inq_params.max_resps = MFW_BT_NUM_REM_DEVICE;
665 inq_params.filter_type = BTA_DM_INQ_CLR;
666
667 /* "initialize" the inquiry data base */
668 mfw_bt_clean_inq_db( );
669 /* store the services we are looking for, so that we can filter the results */
670 mfw_bt_cb.search_services = services;
671 /* find nearby devices */
672 BTA_DmSearch(&inq_params, services, mfw_bt_dm_search_cb );
673 return MFW_BT_SUCCESS;
674
675 }
676
677
678
679
680 /*
681 ** MFW Bluetooth Device Manager Signal Handler Function Definitions
682 */
683 /*******************************************************************************
684
685 $Function: mfw_bt_dm_security_hndlr
686
687 $Description: This function recieves the BTA DM Security events from the Generic Event Handler
688 and either processes them in their entirety or passes them to the MMI for further
689 processing.
690
691 $Returns: MFW_BT_SUCCESS : The signal was handled successfully
692
693 $Arguments: event : Event Id returned from the Bluetooth Module
694 data : pointer to the relevant data returned from the Mluetooth Module
695
696 *******************************************************************************/
697 T_MFW_BT_STATUS mfw_bt_dm_security_hndlr (T_MFW_BT_DM_SEC_EVT event, T_MFW_BT_DM_SEC_SIG_DATA *data)
698 {
699 T_MFW_BT_STATUS retVal = MFW_BT_SUCCESS;
700
701 MFW_BT_TRACE("mfw_bt_dm_security_hndlr");
702
703 switch (event)
704 {
705 case BTA_DM_SYS_START_EVT:
706 {
707 MFW_BT_TRACE("mfw_bt_dm_security_hndlr > BTA_DM_SYS_START_EVT event received");
708 /* now enable bluetooth functionalities before calling other BTA API */
709 BTA_EnableBluetooth(&mfw_bt_dm_security_cb);
710 }
711 break;
712
713 case BTA_DM_ENABLE_EVT:
714 {
715 MFW_BT_TRACE("mfw_bt_dm_security_hndlr > BTA_DM_ENABLE_EVT event received");
716 /* call the enable call-back */
717 mfw_bt_enable_cb( );
718 }
719 break;
720
721 case BTA_DM_DISABLE_EVT:
722 {
723 MFW_BT_TRACE("mfw_bt_dm_security_hndlr > BTA_DM_DISABLE_EVT event received");
724
725 /* stop the BT chipset */
726 BTA_SysStop();
727
728 /* we won't use BT anymore => free the event handler */
729 mfw_bt_ge_disable();
730
731 /* store the new settings */
732 mfw_bt_store_status(FALSE);
733 mfw_bt_cb.is_started = FALSE;
734
735 /* and tell BMI */
736 mfw_bt_signal(E_BT_DISABLE_CMPL, (void *)0);
737 }
738 break;
739
740 case BTA_DM_PIN_REQ_EVT:
741 {
742 /* store the BD ADDR of the remote device */
743 bdcpy(mfw_bt_cb.peer_bdaddr, data->pin_req.bd_addr);
744 /* and forward the signal to BMI */
745 mfw_bt_signal(E_BT_DM_PIN_REQ, data);
746 MFW_BT_TRACE("mfw_bt_dm_security_hndlr > BTA_DM_PIN_REQ_EVT event received");
747 }
748 break;
749
750 case BTA_DM_AUTH_CMPL_EVT:
751 {
752 T_MFW_BT_DM_AUTH_CMPL data_auth;
753 T_MFW_BT_REM_DEVICE device;
754 T_MFW_BT_REM_DEVICE *p_device;
755
756 MFW_BT_TRACE("mfw_bt_dm_security_hndlr > BTA_DM_AUTH_CMPL_EVT event received");
757 /* first, give some feedback to BMI */
758 /* => copy data */
759 memcpy(data_auth.bd_addr, data->auth_cmpl.bd_addr, BD_ADDR_LEN);
760 if( strlen((char*)data->auth_cmpl.bd_name) != 0 )
761 mfwStrncpy((char*)data_auth.bd_name, (const char*)data->auth_cmpl.bd_name, MFW_BT_NAME_LENGTH);
762 data_auth.is_success = data->auth_cmpl.success;
763 /* and forward it */
764 mfw_bt_signal(E_BT_DM_AUTH_CMPL, (void*)&data_auth);
765
766 /* now see if we have to update our data base */
767 p_device = mfw_bt_get_device_info(data->auth_cmpl.bd_addr);
768 if( p_device == NULL )
769 {
770 /* we don't know this device ... */
771 if ( data->auth_cmpl.success == FALSE )
772 /* ... and auth has been rejected: get away from here... */
773 break;
774
775 /* ... but it's trusted. So add it to our DB. This means we have to create a
776 real T_MFW_BT_REM_DEVICE entity, which will be copied */
777 p_device = &device;
778 memset(&device, 0, sizeof( T_MFW_BT_REM_DEVICE ) );
779 }
780
781 /* ok, now update our local DB: get the info we received */
782 memcpy(p_device->bd_addr, data->auth_cmpl.bd_addr, BD_ADDR_LEN);
783 if( strlen((char*)data->auth_cmpl.bd_name) != 0 )
784 mfwStrncpy((char*)p_device->name, (const char*)data->auth_cmpl.bd_name, MFW_BT_NAME_LENGTH);
785 memcpy(p_device->link_key, data->auth_cmpl.key, LINK_KEY_LEN );
786 p_device->link_key_present = data->auth_cmpl.key_present;
787
788 /* we don't modify the other fields => either the already stored ones will be used,
789 either for a new device they will be set to zero. */
790
791 mfw_bt_flash_store_device( p_device );
792 }
793 break;
794
795 case BTA_DM_AUTHORIZE_EVT:
796 {
797 /* keep a trace of the information??? */
798 bdcpy(mfw_bt_cb.peer_bdaddr, data->authorize.bd_addr);
799 strncpy((char*)mfw_bt_cb.peer_name, (char*)data->authorize.bd_name, MFW_BT_NAME_LENGTH);
800 mfw_bt_cb.peer_service = data->authorize.service;
801 /*and forward it to BMI */
802 mfw_bt_signal(E_BT_DM_AUTHORIZE_REQ, data );
803 MFW_BT_TRACE("mfw_bt_dm_security_hndlr > BTA_DM_AUTHORIZE_EVT event received");
804 }
805 break;
806
807 case BTA_DM_LINK_UP_EVT:
808 {
809 /* this is only a "HW" connection, so no service or name needed. Just show BT is busy */
810 MFW_BT_TRACE("mfw_bt_dm_security_hndlr > BTA_DM_LINK_UP_EVT event received");
811 mfw_bt_signal(E_BT_DM_LINK_UP, data );
812 }
813 break;
814
815 case BTA_DM_LINK_DOWN_EVT:
816 {
817 /* just to know BT is idle again */
818 MFW_BT_TRACE("mfw_bt_dm_security_hndlr > BTA_DM_LINK_DOWN_EVT event received");
819 mfw_bt_signal(E_BT_DM_LINK_DOWN, data );
820 }
821 break;
822
823 case BTA_DM_SIG_STRENGTH_EVT:
824 {
825 /* ok, we receive a signal strength indication. Great. */
826 MFW_BT_TRACE("mfw_bt_dm_security_hndlr > BTA_DM_SIG_STRENGTH_EVT event received");
827 mfw_bt_signal(E_BT_DM_SIG_STRENGTH_IND, data );
828 }
829 break;
830
831 default:
832 {
833 /*
834 ** Unexpected Event, set the data sized to -1 to exit with no further action
835 */
836 MFW_BT_TRACE_P1("mfw_bt_dm_security_b > Unexpected Event %d", event);
837 retVal = MFW_BT_INVALID_EVENT;
838 }
839 break;
840
841 }
842
843 return retVal;
844 }
845
846
847
848
849 /*******************************************************************************
850
851 $Function: mfw_bt_dm_search_hndlr
852
853 $Description: This function recieves the BTA DM Search events from the Generic Event Handler
854 and either processes them in their entirety or passes them to the MMI for further
855 processing.
856
857 $Returns: MFW_BT_SUCCESS : The signal was handled successfully
858
859 $Arguments: event : Event Id returned from the Bluetooth Module
860 data : pointer to the relevant data returned from the Mluetooth Module
861
862 *******************************************************************************/
863 T_MFW_BT_STATUS mfw_bt_dm_search_hndlr (T_MFW_BT_DM_SRCH_EVT event, T_MFW_BT_DM_SRCH_SIG_DATA *data)
864 {
865 T_MFW_BT_STATUS retVal = MFW_BT_SUCCESS;
866
867 MFW_BT_TRACE("mfw_bt_dm_search_hndlr");
868
869 /*
870 ** Set the expected data size according to the received event
871 */
872 switch (event)
873 {
874 case BTA_DM_INQ_RES_EVT:
875 {
876 MFW_BT_TRACE("mfw_bt_dm_search_hndlr > BTA_DM_INQ_RES_EVT event received");
877 /* we just received a BD address... Don't even forward this to BMI */
878 MFW_BT_TRACE_P6("DB_ADDR: msg_str%02x:%02x:%02x:%02x:%02x:%02x\n",
879 data->inq_res.bd_addr[0], data->inq_res.bd_addr[1],
880 data->inq_res.bd_addr[2], data->inq_res.bd_addr[3],
881 data->inq_res.bd_addr[4], data->inq_res.bd_addr[5]);
882 mfw_bt_add_inq_device( &(data->inq_res) );
883 }
884 break;
885
886 case BTA_DM_INQ_CMPL_EVT:
887 mfw_bt_signal( E_BT_DM_INQ_CMPL, (void*)&data->inq_cmpl);
888 MFW_BT_TRACE("mfw_bt_dm_search_hndlr > BTA_DM_INQ_CMPL_EVT event received");
889 break;
890
891 case BTA_DM_DISC_RES_EVT:
892 {
893 T_MFW_BT_DM_DISC_RES disc_res_data;
894 T_MFW_BT_REM_DEVICE *p_device_rec = NULL; /*CQ21834 : Not Just needed for discovery, but search also */
895
896 /*
897 ** Do some preliminary initialisation, so that if nothing changes we send the right information
898 */
899 memset(&disc_res_data, 0x00, sizeof(T_MFW_BT_DM_DISC_RES));
900
901 memcpy(disc_res_data.bd_addr, data->disc_res.bd_addr, sizeof(BD_ADDR));
902 memcpy(disc_res_data.name, data->disc_res.bd_name, MFW_BT_NAME_LENGTH);
903 disc_res_data.services = data->disc_res.services;
904 disc_res_data.is_new = TRUE;
905
906 /* if we are doing a discovery on a device */
907 if(mfw_bt_cb.is_discovery == TRUE)
908 {
909 if(data->disc_res.services == 0 )
910 {
911 MFW_BT_TRACE("No service found");
912 }
913 else
914 {
915 p_device_rec = mfw_bt_get_device_info(data->disc_res.bd_addr );
916 if(p_device_rec)
917 {
918 /* we really should find our device! */
919 p_device_rec->services = data->disc_res.services;
920
921 if( p_device_rec->is_new)
922 mfw_bt_add_disc_device((T_MFW_BT_DM_DISC_RES*) p_device_rec);
923 else
924 mfw_bt_flash_store_device(p_device_rec);
925 /* forward the info to BMI */
926
927 /*
928 ** Reset the information for the signal from the known or already discovered database
929 */
930 memcpy(&disc_res_data, p_device_rec, sizeof(T_MFW_BT_DM_DISC_RES));
931 }
932 }
933 }
934 /* we are doing device search. We receive the information about all the found devices.
935 Let's verify if we specified services to look for => if yes, filter the results */
936 else if( mfw_bt_cb.search_services == 0 ||
937 (mfw_bt_cb.search_services & data->disc_res.services))
938 {
939 /*
940 ** CQ21834 : Check to determine whether the device is already known, if so get (and update)
941 ** the information in th eKnown Devices Database
942 */
943 p_device_rec = mfw_bt_get_device_info(data->disc_res.bd_addr );
944
945 /*
946 ** p_device_rec should not be NULL because the device was added to the inquiry database when the inq result
947 ** was recieved if it was not already in the known device database.
948 */
949 if (p_device_rec->is_new == FALSE)
950 {
951 MFW_BT_TRACE("BTA_DM_DISC_RES_EVT > This device is known");
952
953 if (strncmp(p_device_rec->name, (char *)&data->disc_res.bd_name, MFW_BT_NAME_LENGTH) != 0)
954 {
955 mfwStrncpy(p_device_rec->name, (char *)&data->disc_res.bd_name, MFW_BT_NAME_LENGTH);
956 }
957
958 /* Update the device details! */
959 p_device_rec->services |= data->disc_res.services;
960 mfw_bt_flash_store_device(p_device_rec);
961
962 memcpy(&disc_res_data, p_device_rec, sizeof(T_MFW_BT_DM_DISC_RES));
963 }
964
965 /*
966 ** CQ21834: update our database whether the device is known or not, so that if the user removes it from the
967 ** known device database, we will still have the details available.
968 */
969 mfw_bt_add_disc_device( (T_MFW_BT_DM_DISC_RES*) &disc_res_data);
970 }
971
972 MFW_BT_TRACE("mfw_bt_dm_search_hndlr > BTA_DM_DISC_RES_EVT event received");
973 /* and forward the event to BMI */
974 mfw_bt_signal( E_BT_DM_DISC_RES, (void*)&disc_res_data);
975 }
976 break;
977
978 case BTA_DM_DISC_CMPL_EVT:
979 mfw_bt_signal( E_BT_DM_DISC_CMPL, NULL );
980 MFW_BT_TRACE("mfw_bt_dm_search_hndlr > BTA_DM_DISC_CMPL_EVT event received");
981 break;
982
983 case BTA_DM_SEARCH_CANCEL_CMPL_EVT:
984 /* currently, we don't do anything when a search is cancelled. Should we? */
985 MFW_BT_TRACE("mfw_bt_dm_search_hndlr > BTA_DM_SEARCH_CANCEL_CMPL_EVT event received");
986 break;
987
988 default:
989 /*
990 ** Unexpected Event, setthe data sized to -1 to exit with no further action
991 */
992 MFW_BT_TRACE_P1("mfw_bt_dm_search_hndlr > Unexpected Event %d", event);
993 retVal = MFW_BT_INVALID_EVENT;
994
995 }
996
997 return retVal;
998 }
999
1000
1001
1002
1003
1004 /*
1005 ** MFW Bluetooth Device Manager Callback Function Definitions
1006 */
1007 /*******************************************************************************
1008
1009 $Function: mfw_bt_dm_security_b
1010
1011 $Description: This is the Device Manager Security Callback function, a pointer to it is passed
1012 to the Bluetooth Module in the BTA DM Enable function and it is used to return
1013 information from the Bluetooth Module
1014
1015 $Returns: None
1016
1017 $Arguments: event : Event Id returned from the Bluetooth Module
1018 data : pointer to the relevant data returned from the Mluetooth Module
1019
1020 *******************************************************************************/
1021 void mfw_bt_dm_security_cb(T_MFW_BT_DM_SEC_EVT event, T_MFW_BT_DM_SEC_SIG_DATA *data)
1022 {
1023 int dataLen;
1024 T_MFW_BT_STATUS geRetVal = MFW_BT_SUCCESS;
1025
1026 MFW_BT_TRACE("mfw_bt_dm_security_b");
1027
1028 /*
1029 ** Set the expected data size according to the received event
1030 */
1031 switch (event)
1032 {
1033 case BTA_DM_SYS_START_EVT:
1034 dataLen = 0;
1035 break;
1036 case BTA_DM_ENABLE_EVT:
1037 dataLen = sizeof(tBTA_DM_ENABLE);
1038 break;
1039
1040 case BTA_DM_DISABLE_EVT:
1041 dataLen = 0;
1042 break;
1043
1044 case BTA_DM_PIN_REQ_EVT:
1045 dataLen = sizeof(tBTA_DM_PIN_REQ);
1046 break;
1047
1048 case BTA_DM_AUTH_CMPL_EVT:
1049 dataLen = sizeof(tBTA_DM_AUTH_CMPL);
1050 break;
1051
1052 case BTA_DM_AUTHORIZE_EVT:
1053 dataLen = sizeof(tBTA_DM_AUTHORIZE);
1054 break;
1055
1056 case BTA_DM_LINK_UP_EVT:
1057 dataLen = sizeof(tBTA_DM_LINK_UP);
1058 break;
1059
1060 case BTA_DM_LINK_DOWN_EVT:
1061 dataLen = sizeof(tBTA_DM_LINK_DOWN);
1062 break;
1063
1064 case BTA_DM_SIG_STRENGTH_EVT:
1065 dataLen = sizeof(tBTA_DM_SIG_STRENGTH);
1066 break;
1067
1068 default:
1069 /*
1070 ** Unexpected Event, setthe data sized to -1 to exit with no further action
1071 */
1072 MFW_BT_TRACE_P1("mfw_bt_dm_security_b > Unexpected Event %d", event);
1073 dataLen = -1;
1074
1075 }
1076
1077
1078 if (dataLen > 0)
1079 {
1080 /*
1081 ** Data is expected with the received signal
1082 */
1083 if ((void *)data == (void *)0)
1084 {
1085 /*
1086 ** The data pointer is NULL, report the error
1087 */
1088 MFW_BT_TRACE_P1("mfw_bt_dm_security_b > Event : %d, Data Pointer is NULL, but data is expected", event);
1089 }
1090 else
1091 {
1092 /*
1093 ** Post the event and data to the Generic event handler
1094 */
1095 geRetVal = mfw_bt_ge_post_event(MFW_BT_DM_SECURITY, (ULONG)event, (void *)data, dataLen);
1096 }
1097 }
1098 else if (dataLen == 0)
1099 {
1100 /*
1101 ** There is no expected data with the received signal, post the event to the Generic event handler
1102 */
1103 geRetVal = mfw_bt_ge_post_event(MFW_BT_DM_SECURITY, (ULONG)event, (void *)0, 0);
1104 }
1105
1106 if (geRetVal != MFW_BT_SUCCESS)
1107 {
1108 /*
1109 ** There is an error, but there is nothing that can be done other than to report it.
1110 */
1111 MFW_BT_TRACE_P1("mfw_bt_dm_security_b > Failed to post the event. Error %d", geRetVal);
1112 }
1113
1114 return;
1115 }
1116
1117
1118 /*******************************************************************************
1119
1120 $Function: mfw_bt_Dm_Search_Cb
1121
1122 $Description: This is the Device Manager Search Callback function, a pointer to it is passed
1123 to the Bluetooth Module in the BTA DM Search and Discover functions and it is
1124 used to return information from the Bluetooth Module
1125
1126 $Returns: None
1127
1128 $Arguments: event : Event Id returned from the Bluetooth Module
1129 data : pointer to the relevant data returned from the Mluetooth Module
1130
1131 *******************************************************************************/
1132 void mfw_bt_dm_search_cb(T_MFW_BT_DM_SRCH_EVT event, T_MFW_BT_DM_SRCH_SIG_DATA *data)
1133 {
1134 int dataLen;
1135 T_MFW_BT_STATUS geRetVal = MFW_BT_SUCCESS;
1136
1137 MFW_BT_TRACE("mfw_bt_Dm_Search_Cb");
1138
1139 /*
1140 ** Set the expected data size according to the received event
1141 */
1142 switch (event)
1143 {
1144 case BTA_DM_INQ_RES_EVT:
1145 dataLen = sizeof(tBTA_DM_INQ_RES);
1146 break;
1147
1148 case BTA_DM_INQ_CMPL_EVT:
1149 dataLen = sizeof(tBTA_DM_INQ_CMPL);
1150 break;
1151
1152 case BTA_DM_DISC_RES_EVT:
1153 dataLen = sizeof(tBTA_DM_DISC_RES);
1154 break;
1155
1156 case BTA_DM_DISC_CMPL_EVT:
1157 dataLen = 0;
1158 break;
1159
1160 case BTA_DM_SEARCH_CANCEL_CMPL_EVT:
1161 dataLen = 0;
1162 break;
1163
1164
1165 default:
1166 /*
1167 ** Unexpected Event, setthe data sized to -1 to exit with no further action
1168 */
1169 MFW_BT_TRACE_P1("mfw_bt_Dm_Search_Cb > Unexpected Event %d", event);
1170 dataLen = -1;
1171
1172 }
1173
1174
1175 if (dataLen > 0)
1176 {
1177 /*
1178 ** Data is expected with the received signal
1179 */
1180 if ((void *)data == (void *)0)
1181 {
1182 /*
1183 ** The data pointer is NULL, report the error
1184 */
1185 MFW_BT_TRACE_P1("mfw_bt_Dm_Search_Cb > Event : %d, Data Pointer is NULL, but data is expected", event);
1186 }
1187 else
1188 {
1189 /*
1190 ** Post the event and data to the Generic event handler
1191 */
1192 geRetVal = mfw_bt_ge_post_event(MFW_BT_DM_SEARCH, (ULONG)event, (void *)data, dataLen);
1193 }
1194 }
1195 else if (dataLen == 0)
1196 {
1197 /*
1198 ** There is no expected data with the received signal, post the event to the Generic event handler
1199 */
1200 geRetVal = mfw_bt_ge_post_event(MFW_BT_DM_SEARCH, (ULONG)event, (void *)0, 0);
1201 }
1202
1203 if (geRetVal != MFW_BT_SUCCESS)
1204 {
1205 /*
1206 ** There is an error, but there is nothing that can be done other than to report it.
1207 */
1208 MFW_BT_TRACE_P1("mfw_bt_Dm_Search_Cb > Failed to post the event. Error %d", geRetVal);
1209 }
1210
1211 return;
1212 }
1213
1214