comparison src/aci2/bmi/mmiBluetooth.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:: mmiBluetooth.c $|
4 | $Author:: NDH $Revision:: 1 $|
5 | CREATED: 26.04.04 $Modtime:: 26.04.04 10:21 $|
6 | STATE : code |
7 +-------------------------------------------------------------------+
8
9
10 MODULE : MFW_BT
11
12 PURPOSE : This module contains the functions for MFW Bluetooth Management
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 #include "prim.h"
29
30 #else
31
32 #include "STDDEFS.H"
33 #include "custom.h"
34 #include "gsm.h"
35 #include "vsi.h"
36
37 #endif
38
39 #include "message.h" /* included for aci_cmh.h .... */
40 //#include "prim.h" /* included for aci_cmh.h .... */
41 #include "aci_cmh.h" /* included for mfw_sat.h, included for MmiDummy.h, included for MmiMenu.h */
42
43 #include "mfw_mfw.h"
44 #include "mfw_win.h"
45 #include "mfw_icn.h" /* included for mfw_mnu.h */
46 #include "mfw_mnu.h"
47 #include "mfw_tim.h"
48 #include "mfw_kbd.h"
49 #include "mfw_sat.h" /* included for MmiDummy.h, included for MmiMenu.h */
50
51 #include "mfw_bte.h"
52 #include "mfw_bt_dm.h"
53 #include "mfw_bt_dg.h"
54 #include "mfw_bt_ag.h"
55 #include "mfw_bt_op.h"
56 #include "mfw_bt_ft.h"
57 #include "mfw_bt_geh.h"
58 //#include "mfw_bt_temp.h"
59
60 #include "MmiBlkLangDB.h"
61 #include "mmiColours.h"
62 #include "MmiDialogs.h"
63 #include "mmiBluetooth.h"
64
65 #include "MmiDummy.h" /* included for MmiMenu.h */
66 #include "MmiLists.h"
67 #include "MmiMenu.h"
68
69 #include "MmiSoftKeys.h"
70
71 #include "AUIEditor.h"
72
73 /*
74 ** Local Typedefs
75 */
76 typedef struct{
77 MfwHnd bt_win;
78 MfwHnd bt_dev_name_win;
79 MfwHnd bt_pin_req_win;
80 MfwHnd bt_authorize_win;
81 MfwHnd bt_discoverable_timer;
82 MfwHnd bt_connection_timer;
83
84 BOOL bt_isEnabled;
85 BOOL bt_isActive;
86 BOOL bt_stopBtOnDiscoverableTimeout;
87 BOOL bt_DevNameForStartup;
88 UBYTE bt_num_active_connections;
89 } T_MMI_BtData;
90
91
92 typedef struct{
93 T_MMI_CONTROL mmi_control;
94
95 MfwHnd win;
96 MfwHnd bt_auth_info_win;
97 MfwHnd bt_auth_info_editor;
98 MfwHnd bt_auth_menu;
99
100 T_MFW_BT_DM_AUTHORIZE_REQ *bt_auth_req_param;
101 UBYTE *bt_auth_info_text;
102 USHORT bt_auth_info_text_size;
103
104 } T_MMI_BT_Authorise_Data;
105
106
107 typedef struct{
108 T_MMI_CONTROL mmi_control;
109
110 MfwHnd win;
111 MfwHnd bt_dev_name_editor;
112 UBYTE bt_device_name[MFW_BT_NAME_LENGTH+1];
113 T_MFW_BT_DM_DEV_ADDR bt_dev_address; /* CQ21843 - Bt Addr of remote device */
114 T_MFW_BT_REM_DEVICE_INFO *rem_device_info; /* CQ21843 - Global information about the remote device*/
115 } T_MMI_BT_Dev_Name_Data;
116
117
118 typedef struct{
119 T_MMI_CONTROL mmi_control;
120
121 MfwHnd win;
122 MfwHnd bt_pin_req_editor;
123 MfwHnd bt_please_wait_dialog;
124
125 T_MFW_BT_DM_DEV_ADDR bt_pin_req_dev;
126 UBYTE bt_pin_req_buf[MFW_BT_MAX_PIN_CODE_LEN+1];
127
128 T_BT_REQ_RESP bt_required_response;
129 } T_MMI_BT_PIN_Req_Data;
130
131 #if 0
132 typedef struct {
133 T_MFW_BT_DM_DEV_ADDR bd_addr;
134 UBYTE bd_name[MFW_BT_NAME_LENGTH + 1];
135 T_MFW_BT_SERVICE_MASK services;
136 BOOL isPaired;
137 BOOL isKnown;
138 BOOL isTrustued;
139 T_MFW_BT_SERVICE_MASK trustedServices;
140 } T_MMI_BtDevDetails;
141 #endif
142
143 typedef struct{
144 T_MMI_CONTROL srch_bt_control;
145
146 MfwHnd win;
147 MfwHnd srch_bt_cmpnt;
148 MfwHnd srch_bt_pairing_pin_editor;
149 MfwHnd srch_bt_please_wait_dialog;
150 MfwHnd srch_bt_dev_list_win;
151 MfwHnd srch_bt_show_services_win;
152 MfwHnd srch_bt_search_timer;
153
154 T_BT_SEARCH_MODE srch_bt_mode;
155
156 UBYTE bt_pairing_pin_buf[MFW_BT_MAX_PIN_CODE_LEN+1];
157
158 T_BT_REQ_RESP srch_bt_req_resp;
159
160 ListMenuData srch_bt_list_devices_menu_data;
161 ListMenuData srch_bt_show_services_menu_data;
162 UBYTE srch_bt_num_devices;
163 UBYTE srch_bt_device_count;
164 ListCbFunc srch_bt_dev_list_cb;
165 T_MFW_BT_REM_DEVICE_INFO *srch_bt_dev_list;
166 UBYTE srch_bt_cur_dev_idx;
167 ULONG srch_bt_cur_dev_serv_list[BTA_MAX_SERVICE_ID-1];
168 } T_MMI_BtSearchData;
169
170 typedef struct
171 {
172 T_MMI_CONTROL mmi_control;
173 T_MFW_HND win;
174 T_MFW_HND kbd;
175 T_MFW_HND kbd_long;
176 T_MFW_HND menu;
177 T_VOID_FUNC func_cb;
178 T_VOID_FUNC cancel_cb;
179 /*
180 * internal data
181 */
182 }T_bt_menu;
183
184 /*
185 ** Local Defines
186 */
187 #define BT_MAX_DISPLAY_DEV_NAME_LENGTH 20
188
189 #define BT_INFO_SCRN_TIMEOUT 1500
190 #define BT_SEARCH_RESP_TIMEOUT 15000 /* 15 seconds */
191 #define BT_AUTHORISE_RESP_TIMEOUT 30000 /* 30 seconds */
192 #define BT_DISCOVERABLE_DURATION 180000 /* 3 minutes */
193 #define BT_CONNECTION_DURATION 60000 /* 1 minute */
194
195 /*
196 ** Local Function Prototypes
197 */
198 static int mmi_bluetooth_device_mnu_cb(MfwMnu * mnu, MfwMnuItem * item);
199 static void mmi_bluetooth_editor_cb(T_MFW_HND win, USHORT identifier, SHORT reason);
200 static int mmi_bluetooth_search_cb(T_MFW_EVENT evnt, void* para);
201 static int mmi_bluetooth_root_cb(T_MFW_EVENT evnt, void* para);
202 static int mmi_bluetooth_search_timer_cb(MfwEvt e, MfwTim *t);
203 static int mmi_bluetooth_discovery_timer_cb(MfwEvt e, MfwTim *t);
204 static int mmi_bluetooth_connection_timer_cb(MfwEvt e, MfwTim *t);
205 static void mmi_bluetooth_dlg_cb(void);
206 static void mmi_bt_srch_no_device_found_dlg_cb(void);
207 static MfwHnd mmi_bluetooth_show_please_wait(T_MFW_HND parent);
208 static MfwHnd mmi_bluetooth_show_info_callback(T_MFW_HND parent, int str1, int str2, T_VOID_FUNC callback);
209 static MfwHnd mmi_bluetooth_show_info(T_MFW_HND parent, int str1, int str2);
210
211 T_MFW_HND bt_menu_start(MfwHnd parent,MfwMnuAttr* menuAttr,T_VOID_FUNC func_cb);
212 static T_MFW_HND bt_menu_create(MfwHnd parent);
213 static void bt_menu_destroy(MfwHnd window);
214 static void bt_menu (T_MFW_HND win, USHORT event, SHORT value, void * parameter);
215 static int bt_menu_mnu_cb (MfwEvt e, MfwMnu *m);
216 static int bt_menu_win_cb (MfwEvt e, MfwWin *w);
217 static int bt_menu_kbd_cb (MfwEvt e, MfwKbd *k);
218 static int bt_menu_kbd_long_cb (MfwEvt e, MfwKbd *k);
219 static void mmi_bt_authorize_editor_cb(T_MFW_HND win, USHORT identifier, SHORT reason);
220 static int mmi_bt_authorize_display_info(MfwMnu* m, MfwMnuItem* i);
221 static int mmi_bt_authorize_once(MfwMnu* m, MfwMnuItem* i);
222 static int mmi_bt_authorize_always(MfwMnu* m, MfwMnuItem* i);
223 static int mmi_bt_dont_authorize(MfwMnu* m, MfwMnuItem* i);
224 static void mmi_bt_authorize_rsk(void);
225 static int bt_srch_dev_pair (MfwMnu * mnu, MfwMnuItem * item);
226 static int bt_srch_dev_show_services (MfwMnu * mnu, MfwMnuItem * item);
227 static int bt_srch_dev_set_name (MfwMnu * mnu, MfwMnuItem * item); /* CQ21843 - Menu Action Function to set Friendly name for Remote device */
228 static int bt_srch_dev_add_known (MfwMnu * mnu, MfwMnuItem * item);
229 static int bt_srch_dev_rem_known (MfwMnu * mnu, MfwMnuItem * item);
230 static void bt_srch_dev_list_searching_cb(T_MFW_HND Parent, ListMenuData *ListData);
231 static void bt_srch_dev_list_listmnu_cb(T_MFW_HND Parent, ListMenuData * ListData);
232 static void bt_srch_service_list_listmnu_cb(T_MFW_HND Parent, ListMenuData * ListData);
233 static int bt_count_dev_services(T_MFW_BT_SERVICE_MASK services, T_MFW_BT_SERVICE_MASK *srv_mask_arry);
234 static int bt_get_TxtId_for_service(T_MFW_BT_SERVICE_MASK service);
235
236 /*
237 ** Local Static Data
238 */
239 static MfwMnuItem menuBtAuthorizeItems[] =
240 {
241 {0,0,0, (char*) TxtBtInfo, 0, (MenuFunc)mmi_bt_authorize_display_info, item_flag_none},
242 {0,0,0, (char*) TxtBtYesOnce, 0, (MenuFunc)mmi_bt_authorize_once, item_flag_none},
243 {0,0,0, (char*) TxtBtYesAlways, 0, (MenuFunc)mmi_bt_authorize_always, item_flag_none},
244 {0,0,0, (char*) TxtNo, 0, (MenuFunc)mmi_bt_dont_authorize, item_flag_none }
245 };
246
247 static const MfwMnuAttr menuBtAuthorize =
248 {
249 &menuArea,
250 MNU_LEFT | MNU_LIST | MNU_CUR_LINE, /* centered page menu */
251 -1, /* use default font */
252 (MfwMnuItem*)menuBtAuthorizeItems, /* with these items */
253 sizeof(menuBtAuthorizeItems)/sizeof(MfwMnuItem), /* number of items */
254 COLOUR_LIST_XX, /* Colour */
255 TxtBtAuthorize, /* Hdr Id */
256 NULL, /* Background */
257 MNUATTRSPARE /* unused */
258 };
259
260
261 static MfwMnuAttr menuBtSearchListAttr =
262 {
263 &menuArea,
264 MNU_LEFT | MNU_LIST | MNU_CUR_LINE, /* centered page menu */
265 -1, /* use default font */
266 NULL, /* with these items (filled in later) */
267 0, /* number of items (filled in leter) */
268 COLOUR_LIST_XX, /* Colour */
269 TxtNull, /* Hdr Id */
270 NULL, /* Background */
271 MNUATTRSPARE /* unused */
272 };
273
274
275 static MfwMnuAttr menuBtShowServicesListAttr =
276 {
277 &menuArea,
278 MNU_LEFT | MNU_LIST | MNU_CUR_LINE, /* centered page menu */
279 -1, /* use default font */
280 NULL, /* with these items (filled in later) */
281 0, /* number of items (filled in leter) */
282 COLOUR_LIST_XX, /* Colour */
283 TxtNull, /* Hdr Id */
284 NULL, /* Background */
285 MNUATTRSPARE /* unused */
286 };
287
288 static MfwMnuItem menuBtDeviceOptionsItems[] =
289 {
290 {0,0,0, (char*) 0, 0, (MenuFunc)bt_srch_dev_pair, isBtDevicePaired},
291 {0,0,0, (char*) 0, 0, (MenuFunc)bt_srch_dev_pair, isBtDeviceUnPaired},
292 {0,0,0, (char*) 0, 0, (MenuFunc)bt_srch_dev_show_services, item_flag_none},
293 {0,0,0, (char*) 0, 0, (MenuFunc)bt_srch_dev_set_name, isBtDeviceUnknown}, /* CQ21843 - Added Menu option*/
294 {0,0,0, (char*) 0, 0, (MenuFunc)bt_srch_dev_add_known, isBtDeviceKnown},
295 {0,0,0, (char*) 0, 0, (MenuFunc)bt_srch_dev_rem_known, isBtDeviceUnknown},
296 };
297
298 /*
299 ** CQ22023 : The Menu attributes should not be const, because the Header Id is to change depending on the Device Name
300 ** Also MNU_HDRFORMAT_STR has to be added to the Menu Mode to allow a Real-Time string to be used as
301 ** the Header Id.
302 */
303 static MfwMnuAttr menuBtDeviceOptions =
304 {
305 &menuArea,
306 MNU_LEFT | MNU_LIST | MNU_CUR_LINE | MNU_HDRFORMAT_STR, /* centered page menu */
307 -1, /* use default font */
308 (MfwMnuItem*)menuBtDeviceOptionsItems, /* with these items */
309 sizeof(menuBtDeviceOptionsItems)/sizeof(MfwMnuItem), /* number of items */
310 COLOUR_LIST_XX, /* Colour */
311 TxtNull, /* Hdr Id */
312 NULL, /* Background */
313 MNUATTRSPARE /* unused */
314 };
315
316 #if 0
317 static MfwMnuItem menuBtServiceOptionsItems[] =
318 {
319 {0,0,0, (char*) TxtBtAuthorize, 0, (MenuFunc)bt_srch_serv_authorize, isBtServiceTrusted},
320 {0,0,0, (char*) TxtBtUnAuthorize, 0, (MenuFunc)bt_srch_serv_revoke_authorization, isBtServiceNotTrusted},
321 };
322
323 static const MfwMnuAttr menuBtServiceOptions =
324 {
325 &menuArea,
326 MNU_LEFT | MNU_LIST | MNU_CUR_LINE, /* centered page menu */
327 -1, /* use default font */
328 (MfwMnuItem*)menuBtServiceOptionsItems, /* with these items */
329 sizeof(menuBtServiceOptionsItems)/sizeof(MfwMnuItem), /* number of items */
330 COLOUR_LIST_XX, /* Colour */
331 TxtNull, /* Hdr Id */
332 NULL, /* Background */
333 MNUATTRSPARE /* unused */
334 };
335 #endif
336
337 /*
338 ** Bluetooth defined Global Data
339 */
340 T_MMI_BtData bt_data = {0};
341
342 T_MMI_BtSearchData bt_srch_data = {0};
343
344 extern MfwHnd mainMmiLng;
345
346 #if 0
347 /*
348 ** Test Specific Local Typedefs
349 */
350 typedef void (*MfwBtCb) (int, void *);
351
352 /*
353 ** Test Specific Local Defines
354 */
355 #define mmiBtModTestDevMngr 1
356 #define mmiBtModTestDevMngrSrch 2
357 #define mmiBtModTestDevMngrSec 3
358 #define mmiBtModTestDataGw 4
359 #define mmiBtModTestAudioGw 5
360 #define mmiBtModTestObjPush 6
361 #define mmiBtModTestObjPushClient 7
362 #define mmiBtModTestObjPushServer 8
363 #define mmiBtModTestFileTxfr 9
364 #define mmiBtModTestFileTxfrClient 10
365 #define mmiBtModTestFileTxfrServer 11
366
367 /*
368 ** Test Specific Local Static Data
369 */
370 static int btModuleUnderTest = 0;
371 static MfwBtCb btModuleUnderTestCb = 0;
372
373
374 /*
375 ** Module Test Function Definitoins
376 */
377 /*******************************************************************************
378
379 $Function: bluetoothTestDevMngr
380
381 $Description: This function sets a flag for the Test Menu to indicate that it is the Device Manager
382 profile which is under test
383
384 $Returns: None
385
386 $Arguments: None
387
388 *******************************************************************************/
389
390 void bluetoothTestDevMngr (void)
391 {
392 TRACE_EVENT("bluetoothTestDevMngr");
393 }
394
395 /*******************************************************************************
396
397 $Function: bluetoothTestDevMngrSrch
398
399 $Description: This function sets a flag for the Test Menu to indicate that it is the Device Manager
400 (Search) profile which is under test
401
402 $Returns: None
403
404 $Arguments: None
405
406 *******************************************************************************/
407
408 void bluetoothTestDevMngrSrch (void)
409 {
410 TRACE_EVENT("bluetoothTestDevMngr");
411
412 btModuleUnderTest = mmiBtModTestDevMngrSrch;
413 btModuleUnderTestCb = (MfwBtCb)mfw_bt_Dm_Search_Cb;
414 }
415
416 /*******************************************************************************
417
418 $Function: bluetoothTestDevMngrSec
419
420 $Description: This function sets a flag for the Test Menu to indicate that it is the Device Manager
421 (Security) profile which is under test
422
423 $Returns: None
424
425 $Arguments: None
426
427 *******************************************************************************/
428
429 void bluetoothTestDevMngrSec (void)
430 {
431 TRACE_EVENT("bluetoothTestDevMngr");
432
433 btModuleUnderTest = mmiBtModTestDevMngrSec;
434 btModuleUnderTestCb = (MfwBtCb)mfw_bt_Dm_Security_Cb;
435 }
436
437 /*******************************************************************************
438
439 $Function: bluetoothTestDataGw
440
441 $Description: This function sets a flag for the Test Menu to indicate that it is the Data Gateway
442 profile which is under test
443
444 $Returns: None
445
446 $Arguments: None
447
448 *******************************************************************************/
449
450 void bluetoothTestDataGw (void)
451 {
452 TRACE_EVENT("bluetoothTestDataGw");
453
454 btModuleUnderTest = mmiBtModTestDataGw;
455 }
456
457 /*******************************************************************************
458
459 $Function: bluetoothTestAudioGw
460
461 $Description: This function sets a flag for the Test Menu to indicate that it is the Audion Gateway
462 profile which is under test
463
464 $Returns: None
465
466 $Arguments: None
467
468 *******************************************************************************/
469
470 void bluetoothTestAudioGw (void)
471 {
472 TRACE_EVENT("bluetoothTestAudioGw");
473
474 btModuleUnderTest = mmiBtModTestAudioGw;
475 }
476
477 /*******************************************************************************
478
479 $Function: bluetoothTestObjPush
480
481 $Description: This function sets a flag for the Test Menu to indicate that it is the Object Push
482 profile which is under test
483
484 $Returns: None
485
486 $Arguments: None
487
488 *******************************************************************************/
489
490 void bluetoothTestObjPush (void)
491 {
492 TRACE_EVENT("bluetoothTestObjPush");
493
494 btModuleUnderTest = mmiBtModTestObjPush;
495 }
496
497 /*******************************************************************************
498
499 $Function: bluetoothTestFileTxfr
500
501 $Description: This function sets a flag for the Test Menu to indicate that it is the File Transfer
502 profile which is under test
503
504 $Returns: None
505
506 $Arguments: None
507
508 *******************************************************************************/
509
510 void bluetoothTestFileTxfr (void)
511 {
512 TRACE_EVENT("bluetoothTestFileTxfr");
513
514 btModuleUnderTest = mmiBtModTestFileTxfr;
515 }
516
517 /*******************************************************************************
518
519 $Function: bluetoothTestClient
520
521 $Description: This function sets a flag for the Test Menu to indicate that it is either the
522 Object Push or File Transfer Client profiles which are under test
523
524 $Returns: None
525
526 $Arguments: None
527
528 *******************************************************************************/
529
530 void bluetoothTestClient (void)
531 {
532 TRACE_EVENT("bluetoothTestClient");
533
534 if (btModuleUnderTest == mmiBtModTestObjPush)
535 {
536 btModuleUnderTest = mmiBtModTestObjPushClient;
537 btModuleUnderTestCb = (MfwBtCb)mfw_bt_Opc_Cb;
538 }
539 else
540 {
541 btModuleUnderTest = mmiBtModTestFileTxfrClient;
542 btModuleUnderTestCb = (MfwBtCb)mfw_bt_Ftc_Cb;
543 }
544 }
545
546 /*******************************************************************************
547
548 $Function: bluetoothTestServer
549
550 $Description: This function sets a flag for the Test Menu to indicate that it is either the
551 Object Push or File Transfer Server profiles which are under test
552
553 $Returns: None
554
555 $Arguments: None
556
557 *******************************************************************************/
558
559 void bluetoothTestServer (void)
560 {
561 TRACE_EVENT("bluetoothTestServer");
562
563 if (btModuleUnderTest == mmiBtModTestObjPush)
564 {
565 btModuleUnderTest = mmiBtModTestObjPushServer;
566 btModuleUnderTestCb = (MfwBtCb)mfw_bt_Ops_Cb;
567 }
568 else
569 {
570 btModuleUnderTest = mmiBtModTestFileTxfrServer;
571 btModuleUnderTestCb = (MfwBtCb)mfw_bt_Fts_Cb;
572 }
573 }
574
575 /*******************************************************************************
576
577 $Function: mmi_bluetooth_test_single_msg
578
579 $Description: This function test the sending of a single event via the appropriate profile callback
580
581 $Returns: None
582
583 $Arguments: mnu : pointer to the mnu data for the menu which caused this function to be called.
584 item : pointer to the item data from the menu.
585
586 *******************************************************************************/
587
588 GLOBAL int mmi_bluetooth_test_single_msg (MfwMnu* mnu, MfwMnuItem* item)
589 {
590 int event;
591 U8 *sigData = mfwAlloc(sizeof(T_MFW_BT_SIG_DATA));
592
593 TRACE_EVENT("mmi_bluetooth_test_single_msg");
594 memset(sigData, 0x37, sizeof(T_MFW_BT_SIG_DATA));
595
596 switch (btModuleUnderTest)
597 {
598 case mmiBtModTestDevMngrSrch:
599 event = BTA_DM_INQ_RES_EVT;
600 break;
601
602 case mmiBtModTestDevMngrSec:
603 event = BTA_DM_ENABLE_EVT;
604 break;
605
606 case mmiBtModTestDataGw:
607 event = BTA_DG_LISTEN_EVT;
608 break;
609
610 case mmiBtModTestAudioGw:
611 event = BTA_AG_OPEN_EVT;
612 break;
613
614 case mmiBtModTestObjPushClient:
615 event = BTA_OPC_OBJECT_EVT;
616 break;
617
618 case mmiBtModTestObjPushServer:
619 event = BTA_OPS_CLOSE_EVT;
620 break;
621
622 case mmiBtModTestFileTxfrClient:
623 event = BTA_FTC_ENABLE_EVT;
624 break;
625
626 case mmiBtModTestFileTxfrServer:
627 event = BTA_FTS_AUTH_EVT;
628 break;
629
630 default:
631 TRACE_EVENT("mmi_bluetooth_test_single_msg > Invalid Test Module");
632 mfwFree(sigData, sizeof(T_MFW_BT_SIG_DATA));
633 return 1;
634 }
635
636 btModuleUnderTestCb(BTA_DG_LISTEN_EVT, sigData);
637
638 mfwFree(sigData, sizeof(T_MFW_BT_SIG_DATA));
639 return 1;
640 }
641
642 /*******************************************************************************
643
644 $Function: mmi_bluetooth_test_multi_msg
645
646 $Description: This function test the sending of a multiple events via the appropriate profile callback
647
648 $Returns: None
649
650 $Arguments: mnu : pointer to the mnu data for the menu which caused this function to be called.
651 item : pointer to the item data from the menu.
652
653 *******************************************************************************/
654
655 GLOBAL int mmi_bluetooth_test_multi_msg (MfwMnu* mnu, MfwMnuItem* item)
656 {
657 U8 *sigData = mfwAlloc(sizeof(T_MFW_BT_SIG_DATA));
658 int iLoop, iLoopMaxVal;
659 unsigned char chInit;
660
661 TRACE_EVENT("mmi_bluetooth_test_multi_msg");
662
663 chInit = 0x41;
664
665 switch (btModuleUnderTest)
666 {
667 case mmiBtModTestDevMngrSrch:
668 iLoopMaxVal = BTA_DM_DISC_CMPL_EVT;
669 break;
670
671 case mmiBtModTestDevMngrSec:
672 iLoopMaxVal = BTA_DM_SIG_STRENGTH_EVT;
673 break;
674
675 case mmiBtModTestDataGw:
676 iLoopMaxVal = BTA_DG_CLOSE_EVT;
677 break;
678
679 case mmiBtModTestAudioGw:
680 iLoopMaxVal = BTA_AG_AT_CNUM_EVT;
681 break;
682
683 case mmiBtModTestObjPushClient:
684 iLoopMaxVal = BTA_OPC_CLOSE_EVT;
685 break;
686
687 case mmiBtModTestObjPushServer:
688 iLoopMaxVal = BTA_OPS_CLOSE_EVT;
689 break;
690
691 case mmiBtModTestFileTxfrClient:
692 iLoopMaxVal = BTA_FTC_GETFILE_EVT;
693 break;
694
695 case mmiBtModTestFileTxfrServer:
696 iLoopMaxVal = BTA_FTS_AUTH_EVT;
697 break;
698
699 default:
700 TRACE_EVENT("mmi_bluetooth_test_multi_msg > Invalid Test Module");
701 mfwFree(sigData, sizeof(T_MFW_BT_SIG_DATA));
702 return 1;
703 }
704
705 for (iLoop = 0; iLoop <= iLoopMaxVal; iLoop++)
706 {
707 chInit++;
708 memset(sigData, chInit, sizeof(T_MFW_BT_SIG_DATA));
709
710 btModuleUnderTestCb(iLoop, sigData);
711 }
712
713 mfwFree(sigData, sizeof(T_MFW_BT_SIG_DATA));
714
715 return 1;
716 }
717
718 /*******************************************************************************
719
720 $Function: mmi_bluetooth_test_buf_ovrflow
721
722 $Description: This function testS the sending of a multiple events via the appropriate profile callback,
723 causing a buf overflow of the event buffer
724
725 $Returns: None
726
727 $Arguments: mnu : pointer to the mnu data for the menu which caused this function to be called.
728 item : pointer to the item data from the menu.
729
730 *******************************************************************************/
731
732 GLOBAL int mmi_bluetooth_test_buf_ovrflow(MfwMnu* mnu, MfwMnuItem* item)
733 {
734 int event;
735 U8 *sigData = mfwAlloc(sizeof(T_MFW_BT_SIG_DATA));
736 int iLoop, iLoopMaxVal;
737 unsigned char chInit;
738
739 TRACE_EVENT("mmi_bluetooth_test_multi_msg");
740
741 chInit = 0x61;
742
743 switch (btModuleUnderTest)
744 {
745 case mmiBtModTestDevMngrSrch:
746 iLoopMaxVal = BTA_DM_DISC_CMPL_EVT;
747 break;
748
749 case mmiBtModTestDevMngrSec:
750 iLoopMaxVal = BTA_DM_SIG_STRENGTH_EVT;
751 break;
752
753 case mmiBtModTestDataGw:
754 iLoopMaxVal = BTA_DG_CLOSE_EVT;
755 break;
756
757 case mmiBtModTestAudioGw:
758 iLoopMaxVal = BTA_AG_AT_CNUM_EVT;
759 break;
760
761 case mmiBtModTestObjPushClient:
762 iLoopMaxVal = BTA_OPC_CLOSE_EVT;
763 break;
764
765 case mmiBtModTestObjPushServer:
766 iLoopMaxVal = BTA_OPS_CLOSE_EVT;
767 break;
768
769 case mmiBtModTestFileTxfrClient:
770 iLoopMaxVal = BTA_FTC_GETFILE_EVT;
771 break;
772
773 case mmiBtModTestFileTxfrServer:
774 iLoopMaxVal = BTA_FTS_AUTH_EVT;
775 break;
776
777 default:
778 TRACE_EVENT("mmi_bluetooth_test_multi_msg > Invalid Test Module");
779 mfwFree(sigData, sizeof(T_MFW_BT_SIG_DATA));
780 return 1;
781 }
782
783
784 event = 0;
785 for (iLoop = 0; iLoop <= MFW_BT_MAX_SIG_Q_ENTRIES+1; iLoop++)
786 {
787 chInit++;
788 memset(sigData, chInit, sizeof(T_MFW_BT_SIG_DATA));
789
790 btModuleUnderTestCb(event, sigData);
791 event++;
792 if (event > iLoopMaxVal)
793 event = 0;
794 }
795
796 mfwFree(sigData, sizeof(T_MFW_BT_SIG_DATA));
797
798 return 1;
799 }
800 #endif
801
802 /*
803 ** Module Function Definitions
804 */
805
806 /*******************************************************************************
807
808 $Function: isBluetoothActive
809
810 $Description: This function checks to determine whether Bluetooth is enabled
811
812 $Returns: USHORT : 1 is Bluetooth is Enabled, 0 otherwise
813
814 $Arguments: Not Used.
815
816 *******************************************************************************/
817 USHORT isBluetoothActive( struct MfwMnuTag *m, struct MfwMnuAttrTag *ma, struct MfwMnuItemTag *mi )
818 {
819 MFW_BT_TRACE("isBluetoothActive()");
820
821 if (bt_data.bt_isActive)
822 return 1;
823
824 return 0;
825 }
826
827 /*******************************************************************************
828
829 $Function: isBluetoothInactive
830
831 $Description: This function checks to determine whether Bluetooth is disabled
832
833 $Returns: USHORT : 1 is Bluetooth is Disabled, 0 otherwise
834
835 $Arguments: Not Used.
836
837 *******************************************************************************/
838 USHORT isBluetoothInactive ( struct MfwMnuTag *m, struct MfwMnuAttrTag *ma, struct MfwMnuItemTag *mi )
839 {
840 MFW_BT_TRACE("isBluetoothInactive()");
841
842 if (bt_data.bt_isActive == FALSE)
843 return 1;
844
845 return 0;
846 }
847
848
849 /*******************************************************************************
850
851 $Function: mmi_bluetooth_automatic
852
853 $Description: This function performs the necessary steps to enable bluetooth. It creates a dialog,
854 with the MfwRoot as the parent, and calls the MFW BT functions
855
856 $Returns: Always returnd MFW_EVENT_CONSUMED (1)
857
858 $Arguments: mnu : pointer to the mnu data for the menu which caused this function to be called.
859 item : pointer to the item data from the menu.
860
861 *******************************************************************************/
862
863 GLOBAL int mmi_bluetooth_automatic (MfwMnu * mnu, MfwMnuItem * item)
864 {
865 T_MFW_HND win = mfw_parent(mfw_header());
866
867 MFW_BT_TRACE("mmi_bluetooth_automatic()");
868
869 /*
870 ** Create a timed dialog to display the Message "Bluetooth Failed"
871 */
872 mmi_bluetooth_show_info(win, TxtNotAvailable, TxtNull);
873 }
874
875 /*******************************************************************************
876
877 $Function: isBtDevicePaired
878
879 $Description: This function checks to determine whether the active device is Paired or not.
880
881 $Returns: USHORT : 1 is Device is Paired, 0 otherwise
882
883 $Arguments: Not Used.
884
885 *******************************************************************************/
886 USHORT isBtDevicePaired ( MfwMnu *m, MfwMnuAttr *ma, MfwMnuItem *mi )
887 {
888 T_MFW_BT_REM_DEVICE_INFO *cur_device = &bt_srch_data.srch_bt_dev_list[bt_srch_data.srch_bt_cur_dev_idx];
889
890 MFW_BT_TRACE("isBtDevicePaired()");
891
892 if (cur_device->link_key_present != FALSE)
893 return 1;
894
895 return 0;
896 }
897
898 /*******************************************************************************
899
900 $Function: isBtDeviceUnPaired
901
902 $Description: This function is the opposite of isBtDevicePaired (above)
903
904 $Returns: USHORT : 1 is Device is Not Paired, 0 otherwise
905
906 $Arguments: Not Used.
907
908 *******************************************************************************/
909 USHORT isBtDeviceUnPaired( MfwMnu *m, MfwMnuAttr *ma, MfwMnuItem *mi )
910 {
911 T_MFW_BT_REM_DEVICE_INFO *cur_device = &bt_srch_data.srch_bt_dev_list[bt_srch_data.srch_bt_cur_dev_idx];
912
913 MFW_BT_TRACE("isBtDeviceUnPaired()");
914
915 if (cur_device->link_key_present != FALSE)
916 return 0;
917
918 return 1;
919 }
920
921 /*******************************************************************************
922
923 $Function: isBtDeviceKnown
924
925 $Description: This function checks to determine whether the active device is Known or not.
926
927 $Returns: USHORT : 1 is Device is Known, 0 otherwise
928
929 $Arguments: Not Used.
930
931 *******************************************************************************/
932 USHORT isBtDeviceKnown( MfwMnu *m, MfwMnuAttr *ma, MfwMnuItem *mi )
933 {
934 T_MFW_BT_REM_DEVICE_INFO *cur_device = &bt_srch_data.srch_bt_dev_list[bt_srch_data.srch_bt_cur_dev_idx];
935
936 MFW_BT_TRACE("isBtDeviceKnown()");
937
938 if (cur_device->is_new == FALSE)
939 return 1;
940
941 return 0;
942 }
943
944 /*******************************************************************************
945
946 $Function: isBtDeviceUnknown
947
948 $Description: This function is the opposite of isBtDeviceKnown (above).
949
950 $Returns: USHORT : 1 is Device is Not Known, 0 otherwise
951
952 $Arguments: Not Used.
953
954 *******************************************************************************/
955 USHORT isBtDeviceUnknown( MfwMnu *m, MfwMnuAttr *ma, MfwMnuItem *mi )
956 {
957 T_MFW_BT_REM_DEVICE_INFO *cur_device = &bt_srch_data.srch_bt_dev_list[bt_srch_data.srch_bt_cur_dev_idx];
958
959 MFW_BT_TRACE("isBtDeviceUnknown()");
960
961 if (cur_device->is_new == FALSE)
962 return 0;
963
964 return 1;
965 }
966
967 /*
968 ** CQ 21834 : The following function is required to hide a Known Device in the List whem it is removed
969 ** from the Known Devices Database
970 */
971 /*******************************************************************************
972
973 $Function: isListDeviceUnknown
974
975 $Description: This function is determines whether the current device in the known device list
976 is still in the Known Devices Database.
977
978 $Returns: USHORT : 1 is Device is Not Known, 0 otherwise
979
980 $Arguments: Not Used.
981
982 *******************************************************************************/
983 USHORT isListDeviceUnknown( MfwMnu *m, MfwMnuAttr *ma, MfwMnuItem *mi )
984 {
985 int index;
986 int indexFound = 0;
987 MfwMnuItem *mItem;
988 T_MFW_BT_REM_DEVICE_INFO *cur_device;
989
990 index = 0;
991 while ((indexFound == 0) && (index < ma->nItems))
992 {
993 mItem = &(ma->items[index]);
994
995 if (mItem == mi)
996 indexFound = 1;
997 else
998 index++;
999 }
1000
1001 if (indexFound == 1)
1002 {
1003 MFW_BT_TRACE_P1("isListDeviceUnknown() index = %d", index);
1004 }
1005 else
1006 {
1007 MFW_BT_TRACE("isListDeviceUnknown() : Unable to determine Index");
1008 }
1009
1010 cur_device = &bt_srch_data.srch_bt_dev_list[index];
1011
1012 if (cur_device->is_new == FALSE)
1013 return 0;
1014
1015 return 1;
1016 }
1017
1018 /*
1019 ** CQ 21834 : The following function is required to determine whether a "No Devices" entry in the
1020 ** Known Devices list should be visible. Without the "No Devices" Entry the list would
1021 ** be empty, and this is not handled correctly in the BMI.
1022 */
1023 /*******************************************************************************
1024
1025 $Function: isDeviceListEmpty
1026
1027 $Description: This function determines whether there are any entries in the known devices
1028 database.
1029
1030 $Returns: USHORT : 0 if the Known Device Database is Empty, 1 otherwise.
1031
1032 $Arguments: Not Used.
1033
1034 *******************************************************************************/
1035 USHORT isDeviceListEmpty( MfwMnu *m, MfwMnuAttr *ma, MfwMnuItem *mi )
1036 {
1037 int index;
1038 T_MFW_BT_REM_DEVICE_INFO *cur_device;
1039 T_MFW_WIN * win_data;
1040 ListWinInfo * data;
1041
1042 MFW_BT_TRACE("isDeviceListEmpty()");
1043
1044 for (index = 0; index < (ma->nItems -1); index++)
1045 {
1046 cur_device = &bt_srch_data.srch_bt_dev_list[index];
1047
1048 if (cur_device->is_new == FALSE)
1049 return 1;
1050 }
1051
1052 /*
1053 ** The list is otherwise empty so :
1054 ** 1. remove the left soft key
1055 ** 2. ensure that the "No Devices" entry is displayed
1056 */
1057
1058 win_data = ((T_MFW_HDR *)bt_srch_data.srch_bt_dev_list_win)->data;
1059 data = (ListWinInfo *)win_data->user;
1060
1061 data->MenuData.LeftSoftKey = TxtNull;
1062 return 0;
1063 }
1064
1065
1066 /*******************************************************************************
1067
1068 $Function: mmi_bt_init
1069
1070 $Description: This function initializes the Bluetooth functionality on MMI startup
1071
1072 $Returns: none
1073
1074 $Arguments: none.
1075
1076 *******************************************************************************/
1077
1078 void mmi_bt_exit (void)
1079 {
1080 T_MMI_BtData *data = &bt_data;
1081
1082 MFW_BT_TRACE("mmi_bt_exit()");
1083 if (data->bt_isEnabled == FALSE)
1084 return;
1085
1086 mfw_bt_delete(data->bt_win);
1087 timDelete(data->bt_discoverable_timer);
1088 timDelete(data->bt_connection_timer);
1089
1090 mfw_bt_exit();
1091
1092 return;
1093 }
1094
1095 /*******************************************************************************
1096
1097 $Function: mmi_bt_init
1098
1099 $Description: This function initializes the Bluetooth functionality on MMI startup
1100
1101 $Returns: none
1102
1103 $Arguments: none.
1104
1105 *******************************************************************************/
1106
1107 void mmi_bt_init (void)
1108 {
1109 T_MMI_BtData *data = &bt_data;
1110
1111 MFW_BT_TRACE("mmi_bt_init()");
1112
1113 mfw_bt_init(); /* Initialize Bluetooth Module */
1114
1115
1116 data->bt_isEnabled = TRUE;
1117
1118 /*
1119 ** Create a Bluetooth component
1120 */
1121 MFW_BT_TRACE("mmi_bt_init > Creating the MFW_BT component");
1122
1123 if (data->bt_win == (void *)0)
1124 {
1125 data->bt_win = mfw_bt_create(0, E_BT_ALL_SERVICES, (MfwCb)mmi_bluetooth_root_cb);
1126 }
1127
1128 if (data->bt_win == (void *)0)
1129 {
1130 MFW_BT_TRACE("mmi_bt_init > MFW_BT Component Failure");
1131 data->bt_isEnabled = FALSE;
1132 }
1133 else
1134 {
1135
1136 /*
1137 ** Create a Timer component for the "Discoverable" Timeout
1138 */
1139 MFW_BT_TRACE("mmi_bt_init > Creating the discoverable timer");
1140 if (data->bt_discoverable_timer == (void *)0)
1141 data->bt_discoverable_timer = timCreate(0,
1142 BT_DISCOVERABLE_DURATION,
1143 (MfwCb)mmi_bluetooth_discovery_timer_cb);
1144
1145 if (data->bt_discoverable_timer == (void *)0)
1146 {
1147 MFW_BT_TRACE("mmi_bt_init > Discoverable timer creation failed ");
1148 data->bt_isEnabled = FALSE;
1149 /*
1150 ** Timer Compnonent Failed to start, delete previous components
1151 */
1152 mfw_bt_delete(data->bt_win);
1153 }
1154 else
1155 {
1156
1157 /*
1158 ** Create a Timer component for the "Connection" Timeout, when the timeout expires
1159 ** for the device being discoverable, but the is still a BT connection in progress
1160 */
1161 MFW_BT_TRACE("mmi_bt_init > Creating the connection timer");
1162 if (data->bt_connection_timer == (void *)0)
1163 data->bt_connection_timer = timCreate(0,
1164 BT_CONNECTION_DURATION,
1165 (MfwCb)mmi_bluetooth_connection_timer_cb);
1166 if (data->bt_connection_timer == (void *)0)
1167 {
1168 MFW_BT_TRACE("mmi_bt_init > Connection Timer creation failure");
1169 data->bt_isEnabled = FALSE;
1170 /*
1171 ** Timer Compnonent Failed to start, delete previous components
1172 */
1173 mfw_bt_delete(data->bt_win);
1174 timDelete(data->bt_discoverable_timer);
1175 }
1176 else
1177 {
1178 menuBtDeviceOptionsItems[0].str = MmiRsrcGetText(TxtBtPairDevice);
1179 menuBtDeviceOptionsItems[1].str = MmiRsrcGetText(TxtBtChangePassKey);
1180 menuBtDeviceOptionsItems[2].str = MmiRsrcGetText(TxtBtShowServices);
1181 menuBtDeviceOptionsItems[3].str = MmiRsrcGetText(TxtBtSetLocalName); /* CQ21843 - Menu Entry to Allow setting the Friendly Name */
1182 menuBtDeviceOptionsItems[4].str = MmiRsrcGetText(TxtBtAddToKnown);
1183 menuBtDeviceOptionsItems[5].str = MmiRsrcGetText(TxtBtRemoveDevice);
1184 }
1185 }
1186 }
1187 return;
1188
1189 }
1190
1191 /*******************************************************************************
1192
1193 $Function: mmi_bluetooth_on
1194
1195 $Description: This function performs the necessary steps to turn on bluetooth. It will create the
1196 root window if required
1197
1198 $Returns: Always returnd MFW_EVENT_CONSUMED (1)
1199
1200 $Arguments: mnu : pointer to the mnu data for the menu which caused this function to be called.
1201 item : pointer to the item data from the menu.
1202
1203 *******************************************************************************/
1204
1205 GLOBAL int mmi_bluetooth_on (MfwMnu* mnu, MfwMnuItem* item)
1206 {
1207 #if 1 /* Disable this while developing the test harness ... it'll come later */
1208
1209 T_MFW_BT_STATUS btRetVal;
1210
1211 MFW_BT_TRACE("mmi_bluetooth_on()");
1212
1213 if (bt_data.bt_isEnabled == FALSE)
1214 {
1215 /*
1216 ** Create a timed dialog to display the Message "Bluetooth DeActivated"
1217 */
1218 mmi_bluetooth_show_info(0, TxtBluetooth, TxtDeActivated);
1219 }
1220 else
1221 {
1222 btRetVal = mfw_bt_enable(MFW_BT_DEFAULT_VIS);
1223
1224 if (btRetVal != MFW_BT_SUCCESS)
1225 {
1226 MFW_BT_TRACE_P1("mmi_bluetooth() : Attempt to enable Bluetooth Failed with %d", btRetVal);
1227 /*
1228 ** Create a timed dialog to display the Message "Bluetooth Failed"
1229 */
1230 mmi_bluetooth_show_info(0, TxtBluetooth, TxtFailed);
1231 }
1232 }
1233
1234
1235 #else
1236 T_MFW_BT_STATUS mfwBtRetVal;
1237
1238 mfwBtRetVal = mfw_bt_ge_enable();
1239
1240 if (mfwBtRetVal <= 0)
1241 {
1242 /*
1243 ** Create a timed dialog to display the Message "Bluetooth Failed"
1244 */
1245 mmi_bluetooth_show_info(TxtBluetooth, TxtFailed);
1246 }
1247 else
1248 {
1249 /*
1250 ** Create a timed dialog to display the Message "Bluetooth Activated"
1251 */
1252 mmi_bluetooth_show_info(TxtBluetooth, TxtActivated);
1253 }
1254
1255 #endif
1256
1257 return MFW_EVENT_CONSUMED;
1258
1259 }
1260
1261 /*******************************************************************************
1262
1263 $Function: mmi_bluetooth_off
1264
1265 $Description: This function performs the necessary steps to turn off bluetooth
1266
1267 $Returns: MFW_EVENT_CONSUMED
1268
1269 $Arguments: mnu : pointer to the mnu data for the menu which caused this function to be called.
1270 item : pointer to the item data from the menu.
1271
1272 *******************************************************************************/
1273
1274 GLOBAL int mmi_bluetooth_off (MfwMnu* mnu, MfwMnuItem* item)
1275 {
1276 #if 1 /* Disable this while developing the test harness ... it'll come later */
1277 T_MMI_BtData *data = &bt_data;
1278
1279 MFW_BT_TRACE("mmi_bluetooth_off()");
1280
1281 if (data->bt_isEnabled == FALSE)
1282 {
1283 return MFW_EVENT_CONSUMED;
1284 }
1285 else
1286 {
1287 if (data->bt_isActive != FALSE)
1288 {
1289 /*
1290 ** Disable the Bluetooth module
1291 */
1292 mfw_bt_disable();
1293
1294 timStop(data->bt_discoverable_timer);
1295 timStop(data->bt_connection_timer);
1296 }
1297 }
1298 #else
1299 mfw_bt_Ge_Disable();
1300
1301 /*
1302 ** Create a timed dialog to display the Message "Bluetooth DeActivated"
1303 */
1304 mmi_bluetooth_show_info(TxtBluetooth, TxtDeActivated);
1305
1306 #endif
1307
1308 return MFW_EVENT_CONSUMED;
1309 }
1310
1311 /*******************************************************************************
1312
1313 $Function: mmi_bluetooth_change_name
1314
1315 $Description: This function performs the necessary steps to change the name of the local device.
1316 It will start an editor to prompt for the name, and allow the user to cancel the input.
1317
1318 $Returns: MFW_EVENT_CONSUMED
1319
1320 $Arguments: mnu : pointer to the mnu data for the menu which caused this function to be called.
1321 item : pointer to the item data from the menu.
1322
1323 *******************************************************************************/
1324
1325 GLOBAL int mmi_bluetooth_change_name(MfwMnu * mnu, MfwMnuItem * item)
1326 {
1327 T_MFW_BT_STATUS btRetVal;
1328 T_MMI_BtData *data = &bt_data;
1329
1330 MfwHnd win = mfw_parent(mfw_header());
1331
1332 MFW_BT_TRACE("mmi_bluetooth_change_name()"); /* CQ21835 */
1333
1334 if (data->bt_isEnabled == FALSE)
1335 {
1336 /*
1337 ** Create a timed dialog to display the Message "Bluetooth DeActivated"
1338 */
1339 mmi_bluetooth_show_info(0, TxtBluetooth, TxtDeActivated);
1340 }
1341 else if (data->bt_dev_name_win == (void *)0)
1342 {
1343 data->bt_DevNameForStartup = FALSE;
1344
1345 data->bt_dev_name_win = mmi_bt_dev_name_create(win);
1346
1347 if (data->bt_dev_name_win != (void *)0)
1348 {
1349 SEND_EVENT(data->bt_dev_name_win, BT_DEV_NAME_REQ, 0, (void *)0);
1350 }
1351 else
1352 {
1353 MFW_BT_TRACE("mmi_bluetooth_root_cb() : Unable to create Device Name Win!");
1354 }
1355 }
1356 else
1357 {
1358 MFW_BT_TRACE("mmi_bluetooth_root_cb() : Device Name Win already active");
1359 }
1360
1361 return MFW_EVENT_CONSUMED;
1362
1363 }
1364
1365 /*******************************************************************************
1366
1367 $Function: mmi_bluetooth_set_discoverable_on
1368
1369 $Description: This function performs the necessary steps to make this device discoverable, it
1370 will turn on Bluetooth if it is currently off.
1371
1372 $Returns: MFW_EVENT_CONSUMED
1373
1374 $Arguments: mnu : pointer to the mnu data for the menu which caused this function to be called.
1375 item : pointer to the item data from the menu.
1376
1377 *******************************************************************************/
1378
1379 GLOBAL int mmi_bluetooth_set_discoverable_on(MfwMnu * mnu, MfwMnuItem * item)
1380 {
1381 T_MFW_BT_STATUS btRetVal;
1382 T_MMI_BtData *data = &bt_data;
1383
1384 MFW_BT_TRACE("mmi_bluetooth_set_discoverable_on()");
1385
1386 if (data->bt_isEnabled == FALSE)
1387 {
1388 /*
1389 ** Create a timed dialog to display the Message "Bluetooth DeActivated"
1390 */
1391 mmi_bluetooth_show_info(0, TxtBluetooth, TxtDeActivated);
1392 }
1393 else
1394 {
1395 timStop(data->bt_discoverable_timer);
1396 timStop(data->bt_connection_timer);
1397 btRetVal = mfw_bt_dm_set_visibility(TRUE, FALSE); /* Shown, and permanently on */
1398
1399 if (btRetVal != MFW_BT_SUCCESS)
1400 {
1401 MFW_BT_TRACE_P1("mmi_bluetooth_set_discoverable_on() : Set Visibility (TRUE) failed with status : %d", btRetVal);
1402 /*
1403 ** Create a timed dialog to display the Message "Failed"
1404 */
1405 mmi_bluetooth_show_info(0, TxtFailed, TxtNull);
1406 }
1407 else
1408 {
1409 if (data->bt_isActive == FALSE)
1410 {
1411 /*
1412 ** Enable Bluetooth with the appropriate Visibility Mask
1413 */
1414 btRetVal = mfw_bt_enable(MFW_BT_SHOWN);
1415
1416 if (btRetVal != MFW_BT_SUCCESS)
1417 {
1418 MFW_BT_TRACE_P1("mmi_bluetooth_set_discoverable_on() : Attempt to enable Bluetooth Failed with %d", btRetVal);
1419 /*
1420 ** Create a timed dialog to display the Message "Failed"
1421 */
1422 mmi_bluetooth_show_info(0, TxtFailed, TxtNull);
1423 }
1424 }
1425 else
1426 {
1427 /*
1428 ** Create a timed dialog to display the Message "Device Discoverable"
1429 */
1430 mmi_bluetooth_show_info(0, TxtBtDevice, TxtBtDiscoverable);
1431 }
1432 }
1433 }
1434
1435 return MFW_EVENT_CONSUMED;
1436 }
1437
1438 /*******************************************************************************
1439
1440 $Function: mmi_bluetooth_set_discoverable_timed
1441
1442 $Description: This function performs the necessary steps to make this device discoverable
1443 for a preconfigured amount of time. It bluetooth is Off, it will be started. When
1444 the time expiures, thew devicde will become hidden. If there is a connection
1445 open, and bluetooth was started as a result of this request, the timer will be reset,
1446 and when it expires with no connection active, bluetooth will be deactivated.
1447
1448 $Returns: MFW_EVENT_CONSUMED
1449
1450 $Arguments: mnu : pointer to the mnu data for the menu which caused this function to be called.
1451 item : pointer to the item data from the menu.
1452
1453 *******************************************************************************/
1454
1455 GLOBAL int mmi_bluetooth_set_discoverable_timed(MfwMnu * mnu, MfwMnuItem * item)
1456 {
1457 T_MFW_BT_STATUS btRetVal;
1458 T_MMI_BtData *data = &bt_data;
1459
1460 MFW_BT_TRACE("mmi_bluetooth_set_discoverable_timed()");
1461
1462 if (data->bt_isEnabled == FALSE)
1463 {
1464 /*
1465 ** Create a timed dialog to display the Message "Bluetooth DeActivated"
1466 */
1467 mmi_bluetooth_show_info(0, TxtBluetooth, TxtDeActivated);
1468 }
1469 else if (data->bt_isActive == FALSE)
1470 {
1471 /*
1472 ** Enable Bluetooth with the appropriate Visibility Mask
1473 */
1474 btRetVal = mfw_bt_enable(MFW_BT_SHOWN);
1475
1476 if (btRetVal != MFW_BT_SUCCESS)
1477 {
1478 MFW_BT_TRACE_P1("mmi_bluetooth_set_discoverable_timed() : Attempt to enable Bluetooth Failed with %d", btRetVal);
1479 /*
1480 ** Create a timed dialog to display the Message "Failed"
1481 */
1482 mmi_bluetooth_show_info(0, TxtFailed, TxtNull);
1483 }
1484 else
1485 data->bt_stopBtOnDiscoverableTimeout = TRUE;
1486 }
1487 else
1488 {
1489 btRetVal = mfw_bt_dm_set_visibility(TRUE, TRUE);
1490
1491 if (btRetVal != MFW_BT_SUCCESS)
1492 {
1493 MFW_BT_TRACE_P1("mmi_bluetooth_set_discoverable_timed() : Set Visibility (TRUE) failed with status : %d", btRetVal);
1494 /*
1495 ** Create a timed dialog to display the Message "Failed"
1496 */
1497 mmi_bluetooth_show_info(0, TxtFailed, TxtNull);
1498 }
1499 else
1500 {
1501 /*
1502 ** Create a timed dialog to display the Message "Device Discoverable"
1503 */
1504 mmi_bluetooth_show_info(0, TxtBtDevice, TxtBtDiscoverable);
1505 data->bt_stopBtOnDiscoverableTimeout = FALSE;
1506 }
1507 }
1508
1509 timStart(data->bt_discoverable_timer);
1510
1511 return MFW_EVENT_CONSUMED;
1512 }
1513
1514 /*******************************************************************************
1515
1516 $Function: mmi_bluetooth_set_discoverable_off
1517
1518 $Description: This function performs the necessary steps to make this device hidden. It
1519 will not change the state of Bluetooth, if it is on, it will remain on, but hidden,
1520 if it is Off it will remain off.
1521
1522 $Returns: MFW_EVENT_CONSUMED
1523
1524 $Arguments: mnu : pointer to the mnu data for the menu which caused this function to be called.
1525 item : pointer to the item data from the menu.
1526
1527 *******************************************************************************/
1528
1529 GLOBAL int mmi_bluetooth_set_discoverable_off(MfwMnu * mnu, MfwMnuItem * item)
1530 {
1531 T_MFW_BT_STATUS btRetVal;
1532 T_MMI_BtData *data = &bt_data;
1533
1534 MFW_BT_TRACE("mmi_bluetooth_set_discoverable_off()");
1535
1536 if (data->bt_isEnabled == FALSE)
1537 {
1538 /*
1539 ** Create a timed dialog to display the Message "Bluetooth DeActivated"
1540 */
1541 mmi_bluetooth_show_info(0, TxtBluetooth, TxtDeActivated);
1542 }
1543 else
1544 {
1545 timStop(data->bt_discoverable_timer);
1546 timStop(data->bt_connection_timer);
1547
1548 btRetVal = mfw_bt_dm_set_visibility(FALSE, FALSE);
1549
1550 if (btRetVal != MFW_BT_SUCCESS)
1551 {
1552 MFW_BT_TRACE_P1("mmi_bluetooth() : Set Visibility (FALSE) failed with status : %d", btRetVal);
1553 /*
1554 ** Create a timed dialog to display the Message "Failed"
1555 */
1556 mmi_bluetooth_show_info(0, TxtFailed, TxtNull);
1557 }
1558 else
1559 {
1560 mmi_bluetooth_show_info(0, TxtBtDevice, TxtBtHidden);
1561 }
1562 }
1563 return MFW_EVENT_CONSUMED;
1564 }
1565
1566 /*******************************************************************************
1567
1568 $Function: mmi_bluetooth_device_search
1569
1570 $Description: This function performs the necessary steps to search for local bluetooth devices.
1571 It will only be avaiable if in the menu Bluetooth is active. It will start a new window
1572 to specifically handle the search.
1573
1574 $Returns: MFW_EVENT_CONSUMED
1575
1576 $Arguments: mnu : pointer to the mnu data for the menu which caused this function to be called.
1577 item : pointer to the item data from the menu.
1578
1579 *******************************************************************************/
1580
1581 GLOBAL int mmi_bluetooth_device_search(MfwMnu * mnu, MfwMnuItem * item)
1582 {
1583 T_MFW_HND win;
1584 T_MFW_BT_STATUS btRetVal;
1585 T_MMI_BtData *data = &bt_data;
1586 T_MMI_BtSearchData *srch_data = &bt_srch_data;
1587
1588 MFW_BT_TRACE("mmi_bluetooth_device_search()");
1589
1590 if (data->bt_isActive == FALSE)
1591 {
1592 /*
1593 ** Create a timed dialog to display the Message "Bluetooth DeActivated"
1594 */
1595 mmi_bluetooth_show_info(0, TxtBluetooth, TxtDeActivated);
1596 return MFW_EVENT_CONSUMED;
1597 }
1598
1599 if (srch_data->win == (void *)0)
1600 {
1601 win = mfw_parent(mfw_header());
1602
1603 if (mmi_bt_search_create(win) == FALSE)
1604 {
1605 /*
1606 ** Create a timed dialog to display the Message "Failed"
1607 */
1608 mmi_bluetooth_show_info(0, TxtFailed, TxtNull);
1609 return MFW_EVENT_CONSUMED;
1610 }
1611 SEND_EVENT(srch_data->win, BT_DEVICE_SEARCH, 0, 0);
1612 }
1613 else
1614 {
1615 MFW_BT_TRACE("mmi_bluetooth_device_search > win not NULL!!!");
1616
1617 }
1618
1619 return MFW_EVENT_CONSUMED;
1620 }
1621
1622 /*******************************************************************************
1623
1624 $Function: mmi_bluetooth_list_known_devices
1625
1626 $Description: This function performs the necessary steps to search for local bluetooth devices.
1627 It will only be avaiable if in the menu Bluetooth is active. It will start a new window
1628 to specifically handle the search.
1629
1630 $Returns: MFW_EVENT_CONSUMED
1631
1632 $Arguments: mnu : pointer to the mnu data for the menu which caused this function to be called.
1633 item : pointer to the item data from the menu.
1634
1635 *******************************************************************************/
1636
1637 GLOBAL int mmi_bluetooth_list_known_devices(MfwMnu * mnu, MfwMnuItem * item)
1638 {
1639 T_MFW_HND win;
1640 T_MFW_BT_STATUS btRetVal;
1641 T_MMI_BtData *data = &bt_data;
1642 T_MMI_BtSearchData *srch_data = &bt_srch_data;
1643
1644 MFW_BT_TRACE("mmi_bluetooth_list_known_devices()");
1645
1646 if (data->bt_isEnabled == FALSE)
1647 {
1648 /*
1649 ** Create a timed dialog to display the Message "Bluetooth DeActivated"
1650 */
1651 mmi_bluetooth_show_info(0, TxtBluetooth, TxtDeActivated);
1652 return MFW_EVENT_CONSUMED;
1653 }
1654
1655 if (srch_data->win == (void *)0)
1656 {
1657 win = mfw_parent(mfw_header());
1658
1659 if (mmi_bt_search_create(win) == FALSE)
1660 {
1661 /*
1662 ** Create a timed dialog to display the Message "Failed"
1663 */
1664 mmi_bluetooth_show_info(0, TxtFailed, TxtNull);
1665 return MFW_EVENT_CONSUMED;
1666 }
1667 }
1668
1669 SEND_EVENT(srch_data->win, BT_LIST_KNOWN_DEVICES, 0, 0);
1670
1671 return MFW_EVENT_CONSUMED;
1672 }
1673
1674
1675 /*******************************************************************************
1676
1677 $Function: mmi_bluetooth_clear_all_stored_devices
1678
1679 $Description: This function clears all stored devices from FFS.
1680
1681 $Returns: MFW_EVENT_CONSUMED
1682
1683 $Arguments: mnu : pointer to the mnu data for the menu which caused this function to be called.
1684 item : pointer to the item data from the menu.
1685
1686 *******************************************************************************/
1687
1688 GLOBAL int mmi_bluetooth_clear_all_stored_devices(MfwMnu * mnu, MfwMnuItem * item)
1689 {
1690 T_MFW_BT_STATUS btRetVal;
1691 T_MFW_BT_REM_DEVICE *cur_device;
1692 T_MFW_BT_REM_DEVICE *ptr_db_device[MFW_BT_NUM_REM_DEVICE];
1693 UINT8 dev_index;
1694 UINT8 num_of_known_devices;
1695
1696 MFW_BT_TRACE("mmi_bluetooth_clear_all_stored_devices()");
1697
1698 if (bt_data.bt_isEnabled == FALSE)
1699 {
1700 /*
1701 ** Create a timed dialog to display the Message "Bluetooth DeActivated"
1702 */
1703 mmi_bluetooth_show_info(0, TxtBluetooth, TxtDeActivated);
1704 return MFW_EVENT_CONSUMED;
1705 }
1706
1707 mfw_bt_get_device_by_service(BTA_ALL_SERVICE_MASK, &ptr_db_device[0], &num_of_known_devices);
1708
1709 for (dev_index = 0; dev_index < num_of_known_devices; dev_index++)
1710 {
1711 cur_device = ptr_db_device[dev_index];
1712
1713 btRetVal = mfw_bt_dm_delete_device(cur_device->bd_addr);
1714
1715 if (btRetVal != MFW_BT_SUCCESS)
1716 {
1717 MFW_BT_TRACE_P1("mfw_bt_dm_clear_all_stored_dev returned error : %d", btRetVal);
1718 mmi_bluetooth_show_info(0, TxtFailed, TxtNull);
1719 return MFW_EVENT_CONSUMED;
1720 }
1721 }
1722
1723 mmi_bluetooth_show_info(0, TxtBtKnownDevices, TxtDeleted);
1724
1725 return MFW_EVENT_CONSUMED;
1726 }
1727
1728 /*******************************************************************************
1729
1730 $Function: mmi_bt_pin_request_create
1731
1732 $Description: This function performs the necessary steps to create the a window to handle the
1733 PIN Request, pairing process. It will be removed, or rather remove itself on receipt
1734 of the AUTH_CMPL event
1735
1736 $Returns: T_MFW_HND : Window Handle to th eNew Window, Null if failed.
1737
1738 $Arguments: parent : pointer to the parent window.
1739
1740 *******************************************************************************/
1741 T_MFW_HND mmi_bt_pin_request_create(T_MFW_HND parent)
1742 {
1743 T_MMI_BT_PIN_Req_Data *data;
1744 T_MFW_WIN * win;
1745
1746 data = (T_MMI_BT_PIN_Req_Data *)mfwAlloc((U16)sizeof(T_MMI_BT_PIN_Req_Data));
1747
1748 if (data == (void *)0)
1749 return data;
1750
1751 data->win = winCreate(parent, 0, E_WIN_VISIBLE, mmi_bluetooth_win_cb);
1752
1753 if (data->win == (void *)0)
1754 {
1755 /*
1756 ** Failed to start : Free Memory, and exit
1757 */
1758 mfwFree((U8 *)data, (U16)sizeof(T_MMI_BT_PIN_Req_Data));
1759 data = (void *)0;
1760 return data;
1761 }
1762 else
1763 {
1764 /*
1765 ** Setup the Dialog control functions
1766 */
1767 data->mmi_control.dialog = (T_DIALOG_FUNC)mmi_bt_pin_req_cntrl;
1768 data->mmi_control.data = data;
1769
1770 win = ((T_MFW_HDR *)data->win)->data;
1771 win->user = (void *)data;
1772 }
1773
1774 bt_data.bt_pin_req_win = data->win;
1775 return data->win;
1776
1777 }
1778
1779 /*******************************************************************************
1780
1781 $Function: mmi_bluetooth_pin_request_destroy
1782
1783 $Description: This function performs the necessary steps to remove the window handling the
1784 PIN request, tidying up all allocated resources.
1785
1786 $Returns: MfwResOk : Success
1787 MfwResIllHnd : Illegal Window Handler provided
1788
1789 $Arguments: win : Window to be destroyed
1790
1791 *******************************************************************************/
1792 MfwRes mmi_bt_pin_request_destroy(T_MFW_HND win)
1793 {
1794 T_MFW_WIN * win_data;
1795 T_MMI_BT_PIN_Req_Data * data;
1796
1797 if (win == (void *)0)
1798 return MfwResIllHnd;
1799
1800 win_data = ((T_MFW_HDR *) win)->data;
1801 data = (T_MMI_BT_PIN_Req_Data *)win_data->user;
1802
1803 /*
1804 ** Destroy the Window
1805 */
1806 win_delete(data->win);
1807
1808 /*
1809 ** Free the dynamically allocated memory
1810 */
1811 mfwFree((U8 *)data, (U16)sizeof(T_MMI_BT_PIN_Req_Data));
1812
1813 bt_data.bt_pin_req_win = (void *)0;
1814
1815 return MfwResOk;
1816 }
1817
1818
1819 /*******************************************************************************
1820
1821 $Function: mmi_bt_pin_req_cntrl
1822
1823 $Description: This is the dialog control function for the Pin REquest Window. It receives the signals
1824 from the MFW and determines what action, if any, to take.
1825
1826 $Returns: None
1827
1828 $Arguments: win : The pointer to the window handler, so the function can reference the
1829 dynamic user data, if any.
1830 event : The incoming event
1831 value : Generic incoming Parameter, it will be 'event' dependant
1832 parameter : Generic incoming Parameter, it will be 'event' dependant
1833
1834 *******************************************************************************/
1835 void mmi_bt_pin_req_cntrl (T_MFW_HND win, USHORT event, SHORT value, void * parameter)
1836 {
1837 T_MFW_WIN * win_data = ((T_MFW_HDR *) win)->data;
1838 T_MMI_BT_PIN_Req_Data * data = (T_MMI_BT_PIN_Req_Data *)win_data->user;
1839
1840 T_AUI_EDITOR_DATA editor_data;
1841 T_MFW_BT_STATUS btRetVal;
1842
1843 T_MFW_BT_DM_PIN_REQ *pin_req_param;
1844 T_MFW_BT_DM_AUTH_CMPL *auth_cmpl_param;
1845
1846 MFW_BT_TRACE_P1("mmi_bt_pin_req_cntrl() : Event Received : %d", event);
1847
1848 switch (event)
1849 {
1850 case BT_PIN_REQ:
1851 #ifdef NEW_EDITOR
1852 /*
1853 ** Initialise the editor
1854 */
1855 AUI_edit_SetDefault(&editor_data);
1856 AUI_edit_SetMode(&editor_data, ED_MODE_HIDDEN, ED_CURSOR_BAR);
1857
1858 AUI_edit_SetBuffer(&editor_data, ATB_DCS_ASCII, data->bt_pin_req_buf, MFW_BT_MAX_PIN_CODE_LEN);
1859 AUI_edit_SetTextStr(&editor_data, TxtSoftSelect, TxtSoftBack, TxtBtEnterPassKey, TxtNull);
1860 AUI_edit_SetAltTextStr(&editor_data, 1, TxtNull, TRUE, TxtCancel);
1861
1862
1863 AUI_edit_SetEvents(&editor_data, BT_PIN_REQ_EDITOR, TRUE, FOREVER, (T_AUI_EDIT_CB)mmi_bluetooth_editor_cb);
1864
1865 pin_req_param = (T_MFW_BT_DM_PIN_REQ *)parameter;
1866 memcpy(&data->bt_pin_req_dev, &pin_req_param->bd_addr, sizeof(T_MFW_BT_DM_DEV_ADDR));
1867 data->bt_pin_req_editor = AUI_edit_Start(data->win, &editor_data);
1868 #endif
1869 break;
1870
1871 case BT_AUTH_COMPLETE:
1872 auth_cmpl_param = (T_MFW_BT_DM_AUTH_CMPL *)parameter;
1873
1874 if (memcmp(auth_cmpl_param->bd_addr, data->bt_pin_req_dev, sizeof(T_MFW_BT_DM_DEV_ADDR)) != 0)
1875 {
1876 MFW_BT_TRACE("mmi_bt_pin_req_cntrl() > AUTH Complete event with invalid BD Address");
1877 return;
1878 }
1879
1880 if (data->bt_please_wait_dialog != (void *)0)
1881 {
1882 SEND_EVENT(data->bt_please_wait_dialog, DIALOG_DESTROY, 0, 0);
1883
1884 data->bt_please_wait_dialog = (void *)0;
1885 }
1886
1887 if (data->bt_pin_req_editor != (void *)0)
1888 {
1889 /*
1890 ** Destory the current Pin Entry Window, as Bluetooth has timed out the request
1891 */
1892 AUI_edit_Destroy(data->bt_pin_req_editor);
1893
1894 data->bt_pin_req_editor = (void *)0;
1895 memset(data->bt_pin_req_buf, 0x00, MFW_BT_MAX_PIN_CODE_LEN+1);
1896
1897 /*
1898 ** Create a timed dialog to display the Message "Failed"
1899 */
1900 mmi_bluetooth_show_info(0, TxtBtPassKey, TxtBtTimeout);
1901 }
1902 else if (data->bt_required_response == BT_SUCCESS_FAIL_RESP)
1903 {
1904 if (auth_cmpl_param->is_success == FALSE)
1905 {
1906 /*
1907 ** Create a timed dialog to display the Message "Failed"
1908 */
1909 mmi_bluetooth_show_info(0, TxtFailed, TxtNull);
1910 }
1911 else
1912 {
1913 /*
1914 ** Create a timed dialog to display the Message "Pin OK"
1915 */
1916 mmi_bluetooth_show_info(0, TxtPINOK, TxtNull);
1917 }
1918 }
1919
1920 /*
1921 ** Destory the PIN Request Window, the editor has been destroyed and the last response received.
1922 */
1923 mmi_bt_pin_request_destroy(data->win);
1924 break;
1925
1926
1927 case BT_EDITOR_CANCEL:
1928
1929 data->bt_required_response = BT_NO_RESP;
1930
1931 if (value == BT_PIN_REQ_EDITOR)
1932 {
1933 /*
1934 ** The User has cancelled the input from a Pin request,
1935 ** return a FALSE value to the MFW as an indication. Not bothered about the
1936 ** return value as this is a fail anyway!
1937 */
1938 (void)mfw_bt_dm_pin_code((void *)0, 0);
1939
1940 /*
1941 ** The editor will have been destroyed. Reset the Window handler
1942 */
1943 data->bt_pin_req_editor = (void *)0;
1944 }
1945 else
1946 MFW_BT_TRACE_P1("mmi_bt_pin_req_cntrl(), BT_EDITOR_CANCEL event received with unexpected value %d", value);
1947
1948 break;
1949
1950 case BT_EDITOR_SELECT:
1951 if (value == BT_PIN_REQ_EDITOR)
1952 {
1953 data->bt_required_response = BT_SUCCESS_FAIL_RESP;
1954 /*
1955 ** The user has entered a Pin Key, pass it to the MFW for processing
1956 */
1957 btRetVal = mfw_bt_dm_pin_code((void *)&data->bt_pin_req_buf, strlen((void *)&data->bt_pin_req_buf));
1958
1959 /*
1960 ** CQ21957 : The editor will have been destroyed. Reset the Window handler
1961 */
1962 data->bt_pin_req_editor = (void *)0;
1963
1964 if (btRetVal != MFW_BT_SUCCESS)
1965 {
1966 MFW_BT_TRACE_P1("mmi_bt_pin_req_cntrl() : Attempt to set return Pin Code Failed with %d", btRetVal);
1967 }
1968 else
1969 data->bt_please_wait_dialog = mmi_bluetooth_show_please_wait(data->win);
1970 }
1971 else
1972 {
1973 MFW_BT_TRACE_P1("mmi_bt_pin_req_cntrl(), BT_EDITOR_SELECT event received with unexpected value %d", value);
1974 }
1975 break;
1976
1977 default:
1978 MFW_BT_TRACE("mmi_bt_pin_req_cntrl() : Unexpected Event!");
1979 }
1980
1981 return;
1982 }
1983
1984 /*******************************************************************************
1985
1986 $Function: mmi_bt_dev_name_create
1987
1988 $Description: This function performs the necessary steps to create the a window to handle the
1989 Device Name Request. It will be removed, or rather remove itself on returning the
1990 data to the Mfw.
1991
1992 $Returns: T_MFW_HND : Window Handle to the New Window, Null if failed.
1993
1994 $Arguments: parent : pointer to the parent window.
1995
1996 *******************************************************************************/
1997 T_MFW_HND mmi_bt_dev_name_create(T_MFW_HND parent)
1998 {
1999 T_MMI_BT_Dev_Name_Data *data;
2000 T_MFW_WIN * win;
2001
2002 data = (T_MMI_BT_Dev_Name_Data *)mfwAlloc((U16)sizeof(T_MMI_BT_Dev_Name_Data));
2003
2004 if (data == (void *)0)
2005 return data;
2006
2007 data->win = winCreate(parent, 0, E_WIN_VISIBLE, mmi_bluetooth_win_cb);
2008
2009 if (data->win == (void *)0)
2010 {
2011 /*
2012 ** Failed to start : Free Memory, and exit
2013 */
2014 mfwFree((U8 *)data, (U16)sizeof(T_MMI_BT_Dev_Name_Data));
2015 data = (void *)0;
2016 return data;
2017 }
2018 else
2019 {
2020 /*
2021 ** Setup the Dialog control functions
2022 */
2023 data->mmi_control.dialog = (T_DIALOG_FUNC)mmi_bt_dev_name_cntrl;
2024 data->mmi_control.data = data;
2025
2026 win = ((T_MFW_HDR *)data->win)->data;
2027 win->user = (void *)data;
2028 }
2029
2030 bt_data.bt_dev_name_win = data->win;
2031 return data->win;
2032
2033 }
2034
2035 /*******************************************************************************
2036
2037 $Function: mmi_bt_dev_name_destroy
2038
2039 $Description: This function performs the necessary steps to remove the window handling the
2040 Device Name request, tidying up all allocated resources.
2041
2042 $Returns: MfwResOk : Success
2043 MfwResIllHnd : Illegal Window Handler provided
2044
2045 $Arguments: win : Window to be destroyed
2046
2047 *******************************************************************************/
2048 MfwRes mmi_bt_dev_name_destroy(T_MFW_HND win)
2049 {
2050 T_MFW_WIN * win_data;
2051 T_MMI_BT_Dev_Name_Data * data;
2052
2053 if (win == (void *)0)
2054 return MfwResIllHnd;
2055
2056 win_data = ((T_MFW_HDR *) win)->data;
2057 data = (T_MMI_BT_Dev_Name_Data *)win_data->user;
2058
2059 /*
2060 ** Destroy the Window
2061 */
2062 win_delete(data->win);
2063
2064 /*
2065 ** Free the dynamically allocated memory
2066 */
2067 mfwFree((U8 *)data, (U16)sizeof(T_MMI_BT_Dev_Name_Data));
2068
2069 bt_data.bt_dev_name_win = (void *)0;
2070 return MfwResOk;
2071 }
2072
2073
2074 /*******************************************************************************
2075
2076 $Function: mmi_bt_dev_name_cntrl
2077
2078 $Description: This is the dialog control function for the Device Name Request Window. It
2079 receives the signals from the MFW and determines what action, if any, to take.
2080
2081 $Returns: None
2082
2083 $Arguments: win : The pointer to the window handler, so the function can reference the
2084 dynamic user data, if any.
2085 event : The incoming event
2086 value : Generic incoming Parameter, it will be 'event' dependant
2087 parameter : Generic incoming Parameter, it will be 'event' dependant
2088
2089 *******************************************************************************/
2090 void mmi_bt_dev_name_cntrl (T_MFW_HND win, USHORT event, SHORT value, void * parameter)
2091 {
2092 T_MFW_WIN * win_data = ((T_MFW_HDR *) win)->data;
2093 T_MMI_BT_Dev_Name_Data * data = (T_MMI_BT_Dev_Name_Data *)win_data->user;
2094
2095 T_AUI_EDITOR_DATA editor_data;
2096 UBYTE *ptr_device_name;
2097
2098 T_MFW_BT_STATUS btRetVal;
2099
2100 MFW_BT_TRACE_P1("mmi_bt_dev_name_cntrl() : Event Received : %d", event);
2101
2102 switch (event)
2103 {
2104 case BT_DEV_NAME_REQ:
2105 #ifdef NEW_EDITOR
2106 /*
2107 ** Get the current Device Name from the MFW
2108 */
2109 ptr_device_name = mfw_bt_dm_get_local_name();
2110
2111 memcpy(&data->bt_device_name, ptr_device_name, MFW_BT_NAME_LENGTH);
2112
2113 /*
2114 ** Initialise the editor
2115 */
2116 AUI_edit_SetDefault(&editor_data);
2117
2118 AUI_edit_SetBuffer(&editor_data, ATB_DCS_ASCII, data->bt_device_name, MFW_BT_NAME_LENGTH);
2119 AUI_edit_SetTextStr(&editor_data, TxtSoftSelect, TxtSoftBack, TxtBtEnterDeviceName, TxtNull);
2120 AUI_edit_SetAltTextStr(&editor_data, 1, TxtNull, TRUE, TxtCancel);
2121
2122 AUI_edit_SetEvents(&editor_data, BT_DEV_NAME_EDITOR, TRUE, FOREVER, (T_AUI_EDIT_CB)mmi_bluetooth_editor_cb);
2123
2124 data->bt_dev_name_editor = AUI_edit_Start(data->win, &editor_data);
2125 #endif
2126 break;
2127
2128 case BT_SET_REM_DEV_NAME: /* CQ21843 : Get a Friendly name for a remote device */
2129 #ifdef NEW_EDITOR
2130 data->rem_device_info = (T_MFW_BT_REM_DEVICE_INFO *)parameter;
2131
2132 memcpy(&data->bt_dev_address, &data->rem_device_info->bd_addr, sizeof(T_MFW_BT_DM_DEV_ADDR));
2133 memcpy(&data->bt_device_name, data->rem_device_info->name, MFW_BT_NAME_LENGTH);
2134
2135 /*
2136 ** Initialise the editor
2137 */
2138 AUI_edit_SetDefault(&editor_data);
2139
2140 AUI_edit_SetBuffer(&editor_data, ATB_DCS_ASCII, data->bt_device_name, MFW_BT_NAME_LENGTH);
2141 AUI_edit_SetTextStr(&editor_data, TxtSoftSelect, TxtSoftBack, TxtBtEnterDeviceName, TxtNull);
2142 AUI_edit_SetAltTextStr(&editor_data, 1, TxtNull, TRUE, TxtCancel);
2143
2144 AUI_edit_SetEvents(&editor_data, BT_REM_DEV_NAME_EDITOR, TRUE, FOREVER, (T_AUI_EDIT_CB)mmi_bluetooth_editor_cb);
2145
2146 data->bt_dev_name_editor = AUI_edit_Start(data->win, &editor_data);
2147 #endif
2148 break;
2149
2150 case BT_EDITOR_CANCEL:
2151
2152 if (value == BT_DEV_NAME_EDITOR)
2153 {
2154 if (bt_data.bt_DevNameForStartup)
2155 {
2156 /*
2157 ** The User has cancelled the input from a "Device Name" request, which was
2158 ** requested as a result of the startup sequence. Return a FALSE value to the
2159 ** MFW as an indication. Not bothered about the return value as this is a fail anyway!
2160 */
2161 (void)mfw_bt_dm_set_local_name((void *)0);
2162 }
2163
2164 /*
2165 ** The editor will have been destroyed. Reset the Window handler
2166 */
2167 data->bt_dev_name_editor = (void *)0;
2168 }
2169 else if (value == BT_REM_DEV_NAME_EDITOR) /* CQ21843 : Add Editor processing for new action */
2170 {
2171 /*
2172 ** The editor will have been destroyed. Reset the Window handler
2173 */
2174 data->bt_dev_name_editor = (void *)0;
2175 }
2176 else
2177 {
2178 MFW_BT_TRACE_P1("mmi_bt_dev_name_cntrl(), BT_EDITOR_CANCEL event received with unexpected value %d", value);
2179 }
2180
2181 /*
2182 ** Destroy the Device Name Request Window
2183 */
2184 mmi_bt_dev_name_destroy(data->win);
2185 break;
2186
2187 case BT_EDITOR_SELECT:
2188 if (value == BT_DEV_NAME_EDITOR)
2189 {
2190 /*
2191 ** The user has entered a Device Name, pass it to the MFW for processing
2192 */
2193 btRetVal = mfw_bt_dm_set_local_name((void *)&data->bt_device_name);
2194
2195 if (btRetVal != MFW_BT_SUCCESS)
2196 {
2197 MFW_BT_TRACE_P1("mmi_bt_dev_name_cntrl() : Attempt to set Device Name Failed with %d", btRetVal);
2198 }
2199 else
2200 {
2201 /*
2202 ** Create a timed dialog to display the Message "Device Name Set"
2203 */
2204 mmi_bluetooth_show_info(0, TxtBtDeviceName, TxtBtSet);
2205 }
2206
2207 /*
2208 ** CQ21957 : The editor will have been destroyed. Reset the Window handler
2209 */
2210 data->bt_dev_name_editor = (void *)0;
2211 }
2212 else if (value == BT_REM_DEV_NAME_EDITOR) /* CQ21843 : Add Editor processing for new action */
2213 {
2214 /*
2215 ** The user has entered a Device Name, pass it to the MFW for processing
2216 */
2217 btRetVal = mfw_bt_dm_rename_device(data->bt_dev_address, data->bt_device_name);
2218
2219 if (btRetVal != MFW_BT_SUCCESS)
2220 {
2221 MFW_BT_TRACE_P1("mmi_bt_dev_name_cntrl() : Attempt to set Remote Device Name Failed with %d", btRetVal);
2222 }
2223 else
2224 {
2225 /*
2226 ** Create a timed dialog to display the Message "Device Name Set"
2227 */
2228 mmi_bluetooth_show_info(0, TxtBtDeviceName, TxtBtSet);
2229
2230 /*
2231 ** Set the Name in the local Device list, so that the Menu will be updated
2232 */
2233 memcpy(&data->rem_device_info->name, &data->bt_device_name, MFW_BT_NAME_LENGTH);
2234 }
2235
2236 /*
2237 ** CQ21957 : The editor will have been destroyed. Reset the Window handler
2238 */
2239 data->bt_dev_name_editor = (void *)0;
2240 }
2241 else
2242 {
2243 MFW_BT_TRACE_P1("mmi_bt_dev_name_cntrl(), BT_EDITOR_SELECT event received with unexpected value %d", value);
2244 }
2245
2246 /*
2247 ** Destroy the Device Name Request Window
2248 */
2249 mmi_bt_dev_name_destroy(data->win);
2250 break;
2251
2252 default:
2253 MFW_BT_TRACE("mmi_bt_dev_name_cntrl() : Unexpected Event!");
2254 }
2255
2256 return;
2257 }
2258
2259 /*******************************************************************************
2260
2261 $Function: mmi_bt_authorize_create
2262
2263 $Description: This function performs the necessary steps to create the a window to handle the
2264 Authorize Request. It will be removed, or rather remove itself on returning the
2265 data to the Mfw.
2266
2267 $Returns: T_MFW_HND : Window Handle to the New Window, Null if failed.
2268
2269 $Arguments: parent : pointer to the parent window.
2270
2271 *******************************************************************************/
2272 T_MFW_HND mmi_bt_authorize_create(T_MFW_HND parent)
2273 {
2274 T_MMI_BT_Authorise_Data *data;
2275 T_MFW_WIN * win;
2276
2277 data = (T_MMI_BT_Authorise_Data *)mfwAlloc((U16)sizeof(T_MMI_BT_Authorise_Data));
2278
2279 if (data == (void *)0)
2280 return data;
2281
2282 data->win = winCreate(parent, 0, E_WIN_VISIBLE, mmi_bluetooth_win_cb);
2283
2284 if (data->win == (void *)0)
2285 {
2286 /*
2287 ** Failed to start : Free Memory, and exit
2288 */
2289 mfwFree((U8 *)data, (U16)sizeof(T_MMI_BT_Authorise_Data));
2290 data = (void *)0;
2291 return data;
2292 }
2293 else
2294 {
2295 /*
2296 ** Setup the Dialog control functions
2297 */
2298 data->mmi_control.dialog = (T_DIALOG_FUNC)mmi_bt_authorize_cntrl;
2299 data->mmi_control.data = data;
2300
2301 win = ((T_MFW_HDR *)data->win)->data;
2302 win->user = (void *)data;
2303 }
2304
2305 bt_data.bt_authorize_win = data->win;
2306 return data->win;
2307
2308 }
2309
2310 /*******************************************************************************
2311
2312 $Function: mmi_bt_authorize_destroy
2313
2314 $Description: This function performs the necessary steps to remove the window handling for the
2315 Authorize request, tidying up all allocated resources.
2316
2317 $Returns: MfwResOk : Success
2318 MfwResIllHnd : Illegal Window Handler provided
2319
2320 $Arguments: win : Window to be destroyed
2321
2322 *******************************************************************************/
2323 MfwRes mmi_bt_authorize_destroy(T_MFW_HND win)
2324 {
2325 T_MFW_WIN * win_data;
2326 T_MMI_BT_Authorise_Data * data;
2327
2328 if (win == (void *)0)
2329 return MfwResIllHnd;
2330
2331 win_data = ((T_MFW_HDR *) win)->data;
2332 data = (T_MMI_BT_Authorise_Data *)win_data->user;
2333
2334 /*
2335 ** Destroy the Window
2336 */
2337 win_delete(data->win);
2338
2339 /*
2340 ** Free the dynamically allocated memory
2341 */
2342 mfwFree((U8 *)data, (U16)sizeof(T_MMI_BT_Authorise_Data));
2343
2344 bt_data.bt_authorize_win = (void *)0;
2345 return MfwResOk;
2346 }
2347
2348
2349 /*******************************************************************************
2350
2351 $Function: mmi_bt_authorize_cntrl
2352
2353 $Description: This is the dialog control function for the Authorise Request Window. It receives
2354 the signals from the MFW and determines what action, if any, to take.
2355
2356 $Returns: None
2357
2358 $Arguments: win : The pointer to the window handler, so the function can reference the
2359 dynamic user data, if any.
2360 event : The incoming event
2361 value : Generic incoming Parameter, it will be 'event' dependant
2362 parameter : Generic incoming Parameter, it will be 'event' dependant
2363
2364 *******************************************************************************/
2365 void mmi_bt_authorize_cntrl (T_MFW_HND win, USHORT event, SHORT value, void * parameter)
2366 {
2367 T_MFW_WIN * win_data = ((T_MFW_HDR *) win)->data;
2368 T_MMI_BT_Authorise_Data * data = (T_MMI_BT_Authorise_Data *)win_data->user;
2369
2370 T_DISPLAY_DATA display_info;
2371
2372 T_MFW_BT_STATUS btRetVal;
2373
2374 MFW_BT_TRACE_P1("mmi_bluetooth() : Event Received : %d", event);
2375
2376 switch (event)
2377 {
2378 case BT_AUTHORIZE_REQ:
2379 data->bt_auth_req_param = (T_MFW_BT_DM_AUTHORIZE_REQ *)mfwAlloc(sizeof(T_MFW_BT_DM_AUTHORIZE_REQ));
2380
2381 if (data->bt_auth_req_param == (T_MFW_BT_DM_AUTHORIZE_REQ *)0)
2382 {
2383 /*
2384 ** Problems with Memory Allocation, so reject the request this time
2385 */
2386 btRetVal = mfw_bt_dm_authorize_resp(MFW_BT_AUTH_FAIL);
2387 mfwFree((void *)data->bt_auth_req_param, (U16)sizeof(T_MFW_BT_DM_AUTHORIZE_REQ));
2388 mmi_bt_authorize_destroy(data->win);
2389 return;
2390 }
2391
2392 memcpy(data->bt_auth_req_param, parameter, sizeof(T_MFW_BT_DM_AUTHORIZE_REQ));
2393
2394 /*
2395 ** if the length of the Device Name is greater than a predefined limit, truncate it :o)
2396 */
2397 if (strlen((char *)(data->bt_auth_req_param)->bd_name) > BT_MAX_DISPLAY_DEV_NAME_LENGTH)
2398 {
2399 /*
2400 ** Terminate the device name at this maximum length!
2401 ** It will be used for display purposes only!
2402 */
2403 data->bt_auth_req_param->bd_name[BT_MAX_DISPLAY_DEV_NAME_LENGTH] = 0x00;
2404 }
2405
2406 /*
2407 ** Create a popup dialog to prompt the user whether to proceed with the authorization.
2408 ** CQ22022 : Call to dlg_initDisplayData_TextId removed, and dlg_initDisplayData_TextStr updated.
2409 */
2410 dlg_initDisplayData_TextStr( &display_info, TxtSoftOptions, TxtNo, MmiRsrcGetText(TxtBtAuthorize), (char *)(data->bt_auth_req_param)->bd_name, COLOUR_STATUS);
2411
2412 dlg_initDisplayData_events(&display_info, (T_VOID_FUNC)mmi_bt_authorize_dlg_cb, BT_AUTHORISE_RESP_TIMEOUT, KEY_HUP | KEY_LEFT| KEY_RIGHT);
2413
2414 data->bt_auth_info_win = info_dialog(data->win, &display_info);
2415 break;
2416 default:
2417 MFW_BT_TRACE("mmi_bluetooth() : Unexpected Event!");
2418 }
2419
2420 return;
2421 }
2422
2423
2424 /*******************************************************************************
2425
2426 $Function: mmi_bt_authorize_dlg_cb
2427
2428 $Description: This function is the windows callback function for the Authorize Request Dialog.
2429
2430 $Returns: None
2431
2432 $Arguments: win : The pointer to the window handler, so the function can reference the
2433 dynamic user data, if any.
2434 identifier : is a flag set during Dialog Create.
2435 reason : is the event to be processed
2436
2437 *******************************************************************************/
2438 void mmi_bt_authorize_dlg_cb(T_MFW_HND win, UBYTE identifier, UBYTE reason)
2439 {
2440 T_MFW_HND parent = bt_data.bt_authorize_win;
2441 T_MFW_WIN * win_data = ((T_MFW_HDR *) parent)->data;
2442 T_MMI_BT_Authorise_Data * data = (T_MMI_BT_Authorise_Data *)win_data->user;
2443 T_MFW_BT_STATUS btRetVal;
2444
2445 MFW_BT_TRACE("mmi_bt_authorize_dlg_cb()");
2446
2447 switch (reason)
2448 {
2449
2450 case INFO_KCD_LEFT:
2451 /*
2452 ** Create an Authorize Menu and get the Response (Once, Always or No)
2453 */
2454 data->bt_auth_menu = bt_menu_start(data->win, (MfwMnuAttr *)&menuBtAuthorize, (T_VOID_FUNC)mmi_bt_authorize_rsk);
2455
2456 /*
2457 ** CQ22021 : The Dialog is destroyed automatically, reset the win value to NULL
2458 */
2459 data->bt_auth_info_win = 0;
2460 break;
2461
2462 case INFO_KCD_HUP:
2463 case INFO_KCD_RIGHT:
2464 btRetVal = mfw_bt_dm_authorize_resp((U8)MFW_BT_AUTH_FAIL);
2465 mfwFree((void *)data->bt_auth_req_param, (U16)sizeof(T_MFW_BT_DM_AUTHORIZE_REQ));
2466
2467 /*
2468 ** CQ22021 : The Dialog is destroyed automatically, reset the win value to NULL
2469 */
2470 data->bt_auth_info_win = 0;
2471 mmi_bt_authorize_destroy(data->win);
2472 break;
2473 }
2474
2475 return;
2476 }
2477
2478 /*******************************************************************************
2479
2480 $Function: mmi_bluetooth_search_create
2481
2482 $Description: This function performs the necessary steps to create the bluetooth search window,
2483 set up the dialog, and create a Bluetooth Entity within that window. The Bt Search window
2484 is a child of the Bt Root Window, and is used to manage the search for local devices or
2485 the listing of known devices and the subsequent functions available after that
2486
2487 $Returns: BOOL - True is successful, otherwise FALSE
2488
2489 $Arguments: None
2490
2491 *******************************************************************************/
2492
2493 BOOL mmi_bt_search_create (T_MFW_HND parent)
2494 {
2495 T_MMI_BtSearchData *data = &bt_srch_data;
2496 T_MFW_WIN *win;
2497 BOOL retVal = TRUE;
2498
2499 MFW_BT_TRACE("mmi_bt_search_create()");
2500
2501 /*
2502 ** If the Bluetooth Search is already created then there is nothing to do.
2503 */
2504 if ((data->win == (void *)0) ||
2505 (data->srch_bt_cmpnt == (void *)0))
2506 {
2507 /*
2508 ** Create the Bluetooth Search Window
2509 */
2510 MFW_BT_TRACE("mmi_bt_search_create >> Creating BT Search Window");
2511 if (data->win == (void *)0)
2512 data->win = win_create(parent, 0, E_WIN_VISIBLE, (MfwCb)mmi_bluetooth_win_cb);
2513
2514 if (data->win == (void *)0)
2515 {
2516 MFW_BT_TRACE("mmi_bt_search_create >> Create BT Search Window FAILED");
2517 /*
2518 ** Bluetooth Search Failed to start
2519 */
2520 retVal = FALSE;
2521 }
2522 else
2523 {
2524 MFW_BT_TRACE("mmi_bt_search_create >> Configuring Window Dialog");
2525 /*
2526 ** Setup the Dialog control functions
2527 */
2528 data->srch_bt_control.dialog = (T_DIALOG_FUNC)mmi_bt_search_cntrl;
2529 data->srch_bt_control.data = data;
2530
2531 win = ((T_MFW_HDR *)data->win)->data;
2532 win->user = (void *)data;
2533
2534 /*
2535 ** Create a Bluetooth component
2536 */
2537 if (data->srch_bt_cmpnt == (void *)0)
2538 {
2539 MFW_BT_TRACE("mmi_bt_search_create >> Creating MFW_BT Component");
2540 data->srch_bt_cmpnt = mfw_bt_create(data->win, E_BT_ALL_SERVICES, (MfwCb)mmi_bluetooth_search_cb);
2541 }
2542 else
2543 {
2544 MFW_BT_TRACE("mmi_bt_search_create >> MFW_BT Component Already EXISTS????");
2545 }
2546
2547 if (data->srch_bt_cmpnt == (void *)0)
2548 {
2549 retVal = FALSE;
2550 /*
2551 ** Bluetooth Search Compnonent Failed to start
2552 */
2553 winDelete(data->win);
2554 }
2555 else
2556 {
2557 /*
2558 ** Create a Timer component to Timeout a Device Search if no response from BT_Mobile
2559 */
2560 MFW_BT_TRACE("mmi_bt_search_create > Creating the search timer");
2561 if (data->srch_bt_search_timer == (void *)0)
2562 data->srch_bt_search_timer = timCreate(data->win,
2563 BT_SEARCH_RESP_TIMEOUT,
2564 (MfwCb)mmi_bluetooth_search_timer_cb);
2565
2566 if (data->srch_bt_search_timer == (void *)0)
2567 {
2568 MFW_BT_TRACE("mmi_bt_search_create > search timer creation failed ");
2569 /*
2570 ** Timer Compnonent Failed to start, delete previous components
2571 */
2572 mfw_bt_delete(data->srch_bt_cmpnt);
2573 winDelete(data->win);
2574 }
2575 else
2576 {
2577 timStart(data->srch_bt_search_timer);
2578 }
2579 }
2580 }
2581 }
2582
2583 return retVal;
2584
2585 }
2586
2587
2588 /*******************************************************************************
2589
2590 $Function: mmi_bluetooth_destroy
2591
2592 $Description: This function performs the necessary steps to remove the bluetooth, search window
2593 tidying up all allocated resources.
2594
2595 $Returns: None
2596
2597 $Arguments: None
2598
2599 *******************************************************************************/
2600
2601 GLOBAL void mmi_bt_search_destroy (void)
2602 {
2603 T_MMI_BtSearchData * data = &bt_srch_data;
2604
2605 MFW_BT_TRACE("mmi_bluetooth_search_destroy()");
2606
2607 if (data->win == (void *)0)
2608 return;
2609
2610 if (data->srch_bt_pairing_pin_editor != (void *)0)
2611 SEND_EVENT(data->srch_bt_pairing_pin_editor, E_ED_DEINIT, 0, 0);
2612
2613 if (data->srch_bt_please_wait_dialog != (void *)0)
2614 SEND_EVENT(data->srch_bt_please_wait_dialog, DIALOG_DESTROY, 0, 0);
2615
2616 if (data->srch_bt_cmpnt != (void *)0)
2617 mfw_bt_delete(data->srch_bt_cmpnt);
2618
2619 if (data->srch_bt_search_timer != (void *)0)
2620 timDelete(data->srch_bt_search_timer);
2621 winDelete(data->win);
2622
2623 data->win = (void *)0;
2624 data->srch_bt_pairing_pin_editor = (void *)0;
2625 data->srch_bt_please_wait_dialog = (void *)0;
2626 data->srch_bt_dev_list_win = (void *)0;
2627 data->srch_bt_show_services_win = (void *)0;
2628 data->srch_bt_cmpnt = (void *)0;
2629 data->srch_bt_search_timer = (void *)0;
2630
2631
2632 return;
2633 }
2634
2635
2636 /*******************************************************************************
2637
2638 $Function: mmi_bt_search_cntrl
2639
2640 $Description: This is the dialog control function for the Bluetooth Search Window. It receives the signals
2641 from the MFW or BMI and determines what action, if any, to take.
2642
2643 $Returns: None
2644
2645 $Arguments: win : The pointer to the window handler, so the function can reference the
2646 dynamic user data, if any.
2647 event : The incoming event
2648 value : Generic incoming Parameter, it will be 'event' dependant
2649 parameter : Generic incoming Parameter, it will be 'event' dependant
2650
2651 *******************************************************************************/
2652 void mmi_bt_search_cntrl (T_MFW_HND win, USHORT event, SHORT value, void * parameter)
2653 {
2654 T_MFW_WIN * win_data = ((T_MFW_HDR *) win)->data;
2655 T_MMI_BtSearchData * data = (T_MMI_BtSearchData *)win_data->user;
2656
2657 T_DISPLAY_DATA display_info;
2658 T_AUI_EDITOR_DATA editor_data;
2659 BOOL valid;
2660 BOOL btIsDiscoverable;
2661 UBYTE *ptr_device_name;
2662
2663 T_MFW_BT_STATUS btRetVal;
2664
2665 T_MFW_BT_DM_AUTH_CMPL *auth_cmpl_param;
2666 T_MFW_BT_DM_INQ_CMPL *inq_cmpl_param;
2667 T_MFW_BT_DM_DISC_RES *disc_res_param;
2668 T_MFW_BT_REM_DEVICE_INFO *cur_device;
2669
2670 MfwMnuItem *listItem;
2671 T_MFW_BT_REM_DEVICE_INFO *device;
2672 MfwMnuItem *ptr_tempListItem;
2673 T_MFW_BT_REM_DEVICE_INFO *ptr_tempDevDb;
2674 UINT8 num_of_services;
2675
2676
2677 int iLoop;
2678
2679 MFW_BT_TRACE_P1("mmi_bt_search_cntrl() : Event Received : %d", event);
2680
2681 switch (event)
2682 {
2683 case BT_EDITOR_CANCEL:
2684
2685 if ((value == BT_DEV_NAME_EDITOR) ||
2686 (value == BT_REM_DEV_NAME_EDITOR) || /* CQ21843 : Editor Identier has another value */
2687 (value == BT_PIN_REQ_EDITOR))
2688 {
2689 /*
2690 ** Not handled by this window, pass to the root window.
2691 */
2692 MFW_BT_TRACE_P1("mmi_bt_search_cntrl() : Unexpected Editor Cancel Event : value = %d!", value);
2693 }
2694 else if (value == BT_PAIRING_EDITOR)
2695 {
2696 data->srch_bt_req_resp = BT_NOT_EXPECTED;
2697
2698 /*
2699 ** The User has cancelled the input from a Pairing Pin request,
2700 ** the process has not been started. Don't proceed.
2701 */
2702 /*
2703 ** The editor will have been destroyed. Reset the Window handler
2704 */
2705 data->srch_bt_pairing_pin_editor = (void *)0;
2706 }
2707 else
2708 {
2709 MFW_BT_TRACE_P1("mmi_bt_search_cntrl(), BT_EDITOR_CANCEL event received with unknown value %d", value);
2710 }
2711
2712 break;
2713
2714 case BT_EDITOR_SELECT:
2715 if ((value == BT_DEV_NAME_EDITOR) ||
2716 (value == BT_REM_DEV_NAME_EDITOR) || /* CQ21843 : Editor Identier has another value */
2717 (value == BT_PIN_REQ_EDITOR))
2718 {
2719 /*
2720 ** Not handled by this window, pass to the root window.
2721 */
2722 MFW_BT_TRACE_P1("mmi_bt_search_cntrl() : Unexpected Editor Select Event : value = %d!", value);
2723 }
2724 else if (value == BT_PAIRING_EDITOR)
2725 {
2726 /*
2727 ** The editor will have been destroyed. Reset the Window handler
2728 */
2729 data->srch_bt_pairing_pin_editor = (void *)0;
2730
2731 data->srch_bt_req_resp = BT_PAIRED_NOT_RESP;
2732
2733 /*
2734 **The user has entered a Pin Key, now use it in the pairing process
2735 */
2736 cur_device = &data->srch_bt_dev_list[data->srch_bt_cur_dev_idx];
2737
2738 btRetVal = mfw_bt_dm_bond(cur_device->bd_addr,
2739 (void *)&data->bt_pairing_pin_buf,
2740 strlen((void *)&data->bt_pairing_pin_buf));
2741
2742 if (btRetVal != MFW_BT_SUCCESS)
2743 {
2744 MFW_BT_TRACE_P1("mmi_bt_search_cntrl() : Attempt to start Pairing process Failed with %d", btRetVal);
2745 }
2746 else
2747 data->srch_bt_please_wait_dialog = mmi_bluetooth_show_please_wait(data->win);
2748 }
2749 else
2750 {
2751 MFW_BT_TRACE_P1("mmi_bt_search_cntrl(), BT_EDITOR_SELECT event received with unknown value %d", value);
2752 }
2753
2754 break;
2755
2756 case BT_AUTH_COMPLETE:
2757 auth_cmpl_param = (T_MFW_BT_DM_AUTH_CMPL *)parameter;
2758
2759 if (data->srch_bt_req_resp == BT_NOT_EXPECTED)
2760 {
2761 /*
2762 ** Not handled by this window, pass to the root window.
2763 */
2764 MFW_BT_TRACE("mmi_bt_search_cntrl() : Unexpected Auth_Complete Event");
2765 }
2766 else
2767 {
2768 UBYTE iLoop;
2769 T_MFW_BT_REM_DEVICE_INFO *device;
2770
2771 MFW_BT_TRACE_P6("mmi_bt_search_cntrl(), Auth BD_ADDR 0x%02x%02x%02x%02x%02x%02x",
2772 auth_cmpl_param->bd_addr[0], auth_cmpl_param->bd_addr[1],
2773 auth_cmpl_param->bd_addr[2], auth_cmpl_param->bd_addr[3],
2774 auth_cmpl_param->bd_addr[4], auth_cmpl_param->bd_addr[5]);
2775 if (data->srch_bt_please_wait_dialog != (void *)0)
2776 {
2777 SEND_EVENT(data->srch_bt_please_wait_dialog, DIALOG_DESTROY, 0, 0);
2778 data->srch_bt_please_wait_dialog = (void *)0;
2779 }
2780
2781 if (data->srch_bt_req_resp == BT_PAIRED_NOT_RESP)
2782 {
2783 if (auth_cmpl_param->is_success == FALSE)
2784 {
2785 /*
2786 ** Create a timed dialog to display the Message "Pairing Failed"
2787 */
2788 mmi_bluetooth_show_info(data->win, TxtBtPairing, TxtFailed);
2789 }
2790 else
2791 {
2792 /*
2793 ** Create a timed dialog to display the Message "Paired"
2794 */
2795 mmi_bluetooth_show_info(data->win, TxtBtPaired, TxtNull);
2796
2797 /*
2798 ** This will have been as part of a "Device List" either known or local
2799 ** The device will have been added to the known devices list, and will
2800 ** have a link_key present. Update our local data to reflect this.
2801 */
2802 iLoop = 0;
2803 while (iLoop < data->srch_bt_num_devices)
2804 {
2805 device = &data->srch_bt_dev_list[iLoop];
2806
2807 MFW_BT_TRACE_P7("mmi_bt_search_cntrl(), dev_list[%d] BD_ADDR 0x%02x%02x%02x%02x%02x%02x",
2808 iLoop, device->bd_addr[0], device->bd_addr[1], device->bd_addr[2], device->bd_addr[3],
2809 device->bd_addr[4], device->bd_addr[5]);
2810
2811 if (memcmp(&device->bd_addr[0], &auth_cmpl_param->bd_addr[0], BD_ADDR_LEN) == 0 )
2812 {
2813 MFW_BT_TRACE("mmi_bt_search_cntrl() : Auth_Complete Event, device found");
2814 device->link_key_present = TRUE;
2815 device->is_new = FALSE;
2816 iLoop = 0xFF;
2817 }
2818 else
2819 iLoop++;
2820 }
2821 }
2822 }
2823
2824 data->srch_bt_req_resp = BT_NOT_EXPECTED;
2825 }
2826 break;
2827
2828 case BT_LIST_KNOWN_DEVICES:
2829 {
2830 BD_ADDR null_bd_addr;
2831
2832 memset(&null_bd_addr, 0x00, sizeof(BD_ADDR));
2833 /*
2834 ** Get the known devices from the MFW
2835 */
2836 data->srch_bt_mode = BT_MODE_KNOWN_DEVICES;
2837
2838 mfw_bt_dm_get_known_devices(null_bd_addr, BTA_ALL_SERVICE_MASK);
2839 }
2840 break;
2841
2842 case BT_DEVICE_SEARCH:
2843 /*
2844 ** Trigger Bluetooth to search locally for any devices
2845 */
2846 data->srch_bt_mode = BT_MODE_LOCAL_SEARCH;
2847
2848 /* Search for all devices, not service specified */
2849 mfw_bt_dm_search(0);
2850 data->srch_bt_please_wait_dialog = mmi_bluetooth_show_please_wait(data->win);
2851 break;
2852
2853 case BT_INQUIRY_COMPLETE:
2854 MFW_BT_TRACE("mmi_bt_search_cntrl > Recieved the INQUIRY COMPLETE Event");
2855
2856 inq_cmpl_param = (T_MFW_BT_DM_INQ_CMPL *)parameter;
2857
2858 if ((data->srch_bt_mode == BT_MODE_KNOWN_DEVICES) ||
2859 (data->srch_bt_mode == BT_MODE_LOCAL_SEARCH))
2860 {
2861 (void)timStop(data->srch_bt_search_timer);
2862 if (data->srch_bt_please_wait_dialog != (void *)0)
2863 {
2864 SEND_EVENT(data->srch_bt_please_wait_dialog, DIALOG_DESTROY, 0, 0);
2865 data->srch_bt_please_wait_dialog = (void *)0;
2866 }
2867 if (inq_cmpl_param->num_resps == 0)
2868 {
2869 /*
2870 ** Display an Dialog Screen to display "No Devices Found"
2871 */
2872 mmi_bluetooth_show_info_callback(data->win, TxtBtNoDevices, TxtBtFound, mmi_bt_srch_no_device_found_dlg_cb);
2873 data->srch_bt_mode = BT_MODE_NO_SEARCH;
2874 }
2875 else
2876 {
2877 MFW_BT_TRACE("mmi_bt_search_cntrl > Initialising the List");
2878 /*
2879 ** Create the list menu to display the results
2880 */
2881 /* initialization of the dialog data */
2882 data->srch_bt_list_devices_menu_data.ListPosition = 1;/* True cursor position in list menu. */
2883 data->srch_bt_list_devices_menu_data.Font = 0;
2884 data->srch_bt_list_devices_menu_data.LeftSoftKey = TxtNull;
2885 data->srch_bt_list_devices_menu_data.RightSoftKey = TxtCancel;
2886 data->srch_bt_list_devices_menu_data.KeyEvents = KEY_RIGHT;
2887 data->srch_bt_list_devices_menu_data.Reason = 0;
2888 data->srch_bt_list_devices_menu_data.Strings = TRUE;
2889 data->srch_bt_list_devices_menu_data.autoDestroy = FALSE;
2890
2891 data->srch_bt_list_devices_menu_data.Attr = (MfwMnuAttr *)&menuBtSearchListAttr;
2892 data->srch_bt_list_devices_menu_data.Attr->hdrId = TxtSearching;
2893
2894 /*
2895 ** CQ21834 : Special processing for Known Device List.
2896 */
2897 if (data->srch_bt_mode == BT_MODE_KNOWN_DEVICES)
2898 {
2899 /*
2900 ** "Known devices" requires an extra entry, for further details see the comment below
2901 */
2902 data->srch_bt_list_devices_menu_data.Attr->nItems = inq_cmpl_param->num_resps + 1;
2903 data->srch_bt_list_devices_menu_data.ListLength = inq_cmpl_param->num_resps + 1; /* actual number of entries in list menu. */
2904 }
2905 else
2906 {
2907 data->srch_bt_list_devices_menu_data.Attr->nItems = inq_cmpl_param->num_resps;
2908 data->srch_bt_list_devices_menu_data.ListLength = inq_cmpl_param->num_resps; /* actual number of entries in list menu. */
2909 }
2910
2911
2912 data->srch_bt_list_devices_menu_data.List = (MfwMnuItem *)mfwAlloc(data->srch_bt_list_devices_menu_data.ListLength * sizeof (MfwMnuItem));
2913
2914 if (data->srch_bt_list_devices_menu_data.List != (MfwMnuItem *)0)
2915 {
2916 MfwMnuItem *listItem;
2917
2918 MFW_BT_TRACE("mmi_bt_search_cntrl > List Memory Allocated successfully");
2919 /*
2920 ** Initialise the memory to 0x00
2921 */
2922 memset(data->srch_bt_list_devices_menu_data.List, 0x00, data->srch_bt_list_devices_menu_data.ListLength * sizeof (MfwMnuItem));
2923
2924 for (iLoop = 0; iLoop <data->srch_bt_list_devices_menu_data.ListLength; iLoop++)
2925 {
2926 listItem = &data->srch_bt_list_devices_menu_data.List[iLoop];
2927
2928 listItem->str = MmiRsrcGetText(TxtPleaseWait);
2929 listItem->menu = (MfwMnuAttr *)&menuBtDeviceOptions;
2930 listItem->func = (MenuFunc)mmi_bluetooth_device_mnu_cb;
2931 listItem->flagFunc = (FlagFunc)item_flag_hide;
2932 }
2933
2934 /*
2935 ** CQ21834 : If we are displaying a list of known devices, then if ALL the devices
2936 ** are removed from the list, there must be another entry to display otherwise
2937 ** the D-Sample will reset because it will enter an infinite loop. This is overcome
2938 ** by added an extra (an normally hidden) entry which will display "No Devices".
2939 */
2940 if (data->srch_bt_mode == BT_MODE_KNOWN_DEVICES)
2941 {
2942 listItem = &data->srch_bt_list_devices_menu_data.List[inq_cmpl_param->num_resps];
2943
2944 listItem->str = MmiRsrcGetText(TxtBtNoDevices);
2945 listItem->menu = (MfwMnuAttr *)0;
2946 listItem->func = (MenuFunc)0;
2947 listItem->flagFunc = (FlagFunc)isDeviceListEmpty;
2948 }
2949 }
2950
2951 data->srch_bt_dev_list_cb = (ListCbFunc)bt_srch_dev_list_searching_cb;
2952 data->srch_bt_dev_list_win = (void *)0;
2953
2954 /*
2955 ** Create a dynamic memory pool to store the necessary data for the following menus
2956 */
2957 data->srch_bt_num_devices = inq_cmpl_param->num_resps;
2958 data->srch_bt_dev_list = (T_MFW_BT_REM_DEVICE_INFO *)mfwAlloc(sizeof(T_MFW_BT_REM_DEVICE_INFO) * data->srch_bt_num_devices);
2959
2960 data->srch_bt_device_count = 0;
2961 }
2962 }
2963 break;
2964
2965 case BT_DISCOVER_RESULT:
2966
2967 disc_res_param = (T_MFW_BT_DM_DISC_RES *)parameter;
2968
2969 if (!mfw_bt_dm_is_discover())
2970 {
2971 /* We get here at the end of inquiry process */
2972 /*
2973 ** If the mode is 'LIST COMPLETE' at this point it is because the user cancel the search but there
2974 ** were device events queued ... ignore them.
2975 */
2976 if ((data->srch_bt_dev_list) &&
2977 (data->srch_bt_list_devices_menu_data.List) &&
2978 ((data->srch_bt_mode == BT_MODE_KNOWN_DEVICES) ||
2979 (data->srch_bt_mode == BT_MODE_LOCAL_SEARCH)))
2980 {
2981
2982 if (data->srch_bt_dev_list_win != (void *)0)
2983 {
2984 /*
2985 ** The menu is recreated on each device received because the user may decide to halt
2986 ** the search at any point. For Known devices the menu is created at the end because
2987 ** The reponse for ALL devices is immediate.
2988 ** Delete the Menu window, as it will be recreated at the end of this operation
2989 */
2990 listsDestroy(data->srch_bt_dev_list_win);
2991 }
2992
2993 listItem = &data->srch_bt_list_devices_menu_data.List[data->srch_bt_device_count];
2994 device = &data->srch_bt_dev_list[data->srch_bt_device_count];
2995
2996 memcpy(device, disc_res_param, sizeof(T_MFW_BT_REM_DEVICE_INFO));
2997
2998 listItem->str = device->name;
2999
3000 /*
3001 ** CQ21834 : For Known Devices, the device should be hidden in the list if the "Remove Device" menu
3002 ** option is selected.
3003 */
3004 if (data->srch_bt_mode == BT_MODE_KNOWN_DEVICES)
3005 listItem->flagFunc = (FlagFunc)isListDeviceUnknown;
3006 else
3007 listItem->flagFunc = (FlagFunc)item_flag_none;
3008
3009 MFW_BT_TRACE_P3("mmi_bt_search_cntrl > Idx %d : Device Name : %s, Item Str %s",
3010 data->srch_bt_device_count,
3011 device->name,
3012 listItem->str);
3013
3014 data->srch_bt_device_count++;
3015
3016 if (data->srch_bt_device_count == data->srch_bt_num_devices)
3017 {
3018 data->srch_bt_list_devices_menu_data.Attr->hdrId = TxtBtDevices;
3019
3020 data->srch_bt_list_devices_menu_data.LeftSoftKey = TxtSoftOptions;
3021 data->srch_bt_list_devices_menu_data.RightSoftKey = TxtSoftBack;
3022 data->srch_bt_list_devices_menu_data.KeyEvents = KEY_CLEAR | KEY_RIGHT | KEY_LEFT | KEY_MNUUP | KEY_MNUDOWN |KEY_HUP;
3023 data->srch_bt_list_devices_menu_data.autoDestroy = TRUE;
3024 data->srch_bt_mode = BT_MODE_LIST_COMPLETE;
3025
3026 data->srch_bt_dev_list_cb = (ListCbFunc)bt_srch_dev_list_listmnu_cb;
3027 }
3028
3029 if ((data->srch_bt_mode == BT_MODE_LOCAL_SEARCH) ||
3030 (data->srch_bt_mode == BT_MODE_LIST_COMPLETE))
3031 {
3032 /*
3033 ** Recreate the menu with the new details;
3034 */
3035 if (listDisplayListMenu(data->win, &data->srch_bt_list_devices_menu_data, data->srch_bt_dev_list_cb, FALSE) != LISTS_FAIL)
3036 data->srch_bt_dev_list_win = data->srch_bt_list_devices_menu_data.win;
3037 }
3038 }
3039 }
3040 else
3041 {
3042 /* We get here at the end of services discovery process */
3043
3044 if (data->srch_bt_please_wait_dialog != (void *)0)
3045 {
3046 SEND_EVENT(data->srch_bt_please_wait_dialog, DIALOG_DESTROY, 0, 0);
3047 data->srch_bt_please_wait_dialog = (void *)0;
3048 }
3049
3050 device = &data->srch_bt_dev_list[data->srch_bt_cur_dev_idx];
3051
3052 device->services = disc_res_param->services;
3053
3054 MFW_BT_TRACE("mmi_bt_search_cntrl > Memset srch_bt_cur_dev_serv_list to 0x00 ... ");
3055
3056 memset(data->srch_bt_cur_dev_serv_list, 0x00, (sizeof(ULONG)*(BTA_MAX_SERVICE_ID-1)));
3057
3058 num_of_services = bt_count_dev_services(device->services,
3059 data->srch_bt_cur_dev_serv_list);
3060
3061 MFW_BT_TRACE("mmi_bt_search_cntrl > Initialising the List Data");
3062 /*
3063 ** Create the list menu to display the results
3064 */
3065 /* initialization of the dialog data */
3066 data->srch_bt_show_services_menu_data.ListPosition = 1;/* True cursor position in list menu. */
3067 data->srch_bt_show_services_menu_data.Font = 0;
3068 data->srch_bt_show_services_menu_data.LeftSoftKey = TxtNull;
3069 data->srch_bt_show_services_menu_data.RightSoftKey = TxtSoftBack;
3070 data->srch_bt_show_services_menu_data.KeyEvents = KEY_CLEAR | KEY_RIGHT | KEY_MNUUP | KEY_MNUDOWN |KEY_HUP;
3071 data->srch_bt_show_services_menu_data.Reason = 0;
3072 data->srch_bt_show_services_menu_data.Strings = FALSE;
3073 data->srch_bt_show_services_menu_data.autoDestroy = TRUE;
3074
3075 data->srch_bt_show_services_menu_data.Attr = (MfwMnuAttr *)&menuBtShowServicesListAttr;
3076 data->srch_bt_show_services_menu_data.Attr->hdrId = TxtBtServices;
3077 data->srch_bt_show_services_menu_data.Attr->nItems = num_of_services;
3078
3079 data->srch_bt_show_services_menu_data.ListLength = num_of_services; /* actual number of entries in list menu. */
3080 data->srch_bt_show_services_menu_data.List = (MfwMnuItem *)mfwAlloc(data->srch_bt_show_services_menu_data.ListLength * sizeof (MfwMnuItem));
3081
3082 if (data->srch_bt_show_services_menu_data.List != (MfwMnuItem *)0)
3083 {
3084 /*
3085 ** Initialise the memory to 0x00
3086 */
3087 memset(data->srch_bt_show_services_menu_data.List, 0x00, data->srch_bt_show_services_menu_data.ListLength * sizeof (MfwMnuItem));
3088
3089 for (iLoop = 0; iLoop < data->srch_bt_show_services_menu_data.ListLength; iLoop++)
3090 {
3091 listItem = &data->srch_bt_show_services_menu_data.List[iLoop];
3092
3093 listItem->str =(char *)bt_get_TxtId_for_service(data->srch_bt_cur_dev_serv_list[iLoop]);
3094 listItem->flagFunc = (FlagFunc)item_flag_none;
3095 }
3096
3097 MFW_BT_TRACE("mmi_bt_search_cntrl > Displaying the List Menu!");
3098
3099 if (listDisplayListMenu(data->win, &data->srch_bt_show_services_menu_data, (ListCbFunc)bt_srch_service_list_listmnu_cb, FALSE) != LISTS_FAIL)
3100 data->srch_bt_show_services_win = data->srch_bt_show_services_menu_data.win;
3101 }
3102 else
3103 {
3104 mmi_bluetooth_show_info(data->win, TxtFailed, TxtNull);
3105 }
3106 }
3107
3108
3109
3110 break;
3111
3112 case BT_DISCOVER_COMPLETE:
3113 /*
3114 ** CQ 21838 : This event signifies the end of the discover process, this event shoulkd not be ignored.
3115 **
3116 ** If the results for all the expected devices have been received then there will be nothing else to do,
3117 ** otherwise this signal will have to trigger the end of the search. If no device results had been
3118 ** reported, then the "No Devices Found".
3119 */
3120
3121 if (!mfw_bt_dm_is_discover())
3122 {
3123 if (data->srch_bt_device_count != data->srch_bt_num_devices)
3124 {
3125 if (data->srch_bt_device_count == 0)
3126 {
3127 /*
3128 ** If No devices have been reported display a dialog
3129 */
3130 mmi_bluetooth_show_info_callback(data->win, TxtBtNoDevices, TxtBtFound, mmi_bt_srch_no_device_found_dlg_cb);
3131
3132 /*
3133 ** Destroy the memory allocated when the inquiry complete was received
3134 */
3135 mfwFree((U8 *)data->srch_bt_list_devices_menu_data.List,
3136 (data->srch_bt_list_devices_menu_data.ListLength * sizeof (MfwMnuItem)));
3137
3138 mfwFree((U8 *)data->srch_bt_dev_list,
3139 (sizeof(T_MFW_BT_REM_DEVICE_INFO) * data->srch_bt_num_devices));
3140
3141 data->srch_bt_num_devices = 0;
3142 data->srch_bt_mode = BT_MODE_NO_SEARCH;
3143 }
3144 else
3145 {
3146 /*
3147 ** There are devices which have been reported.
3148 ** Change the mode of the list
3149 */
3150 data->srch_bt_mode = BT_MODE_LIST_COMPLETE;
3151
3152 /*
3153 ** Destroy the window and recreate it
3154 */
3155 listsDestroy(data->srch_bt_dev_list_win);
3156
3157 /*
3158 ** Allocate memory to copy the devices already listed, copy the active data,
3159 ** and free the memory set aside for ALL the devices to be listed.
3160 **
3161 ** This should NOT be possible for the known device list, so there is no need to take account of the
3162 ** "No Devices" list entry
3163 */
3164
3165 ptr_tempListItem = (MfwMnuItem *)mfwAlloc(data->srch_bt_device_count * sizeof(MfwMnuItem));
3166 if (ptr_tempListItem != (MfwMnuItem *)0)
3167 {
3168 /*
3169 ** Copy the list of items
3170 */
3171 memcpy(ptr_tempListItem, data->srch_bt_list_devices_menu_data.List, (data->srch_bt_device_count * sizeof(MfwMnuItem)));
3172
3173 /*
3174 ** Free the first (and larger) list
3175 */
3176 mfwFree((U8 *)data->srch_bt_list_devices_menu_data.List, (U16)(data->srch_bt_list_devices_menu_data.ListLength * sizeof(MfwMnuItem)));
3177
3178 data->srch_bt_list_devices_menu_data.List = ptr_tempListItem;
3179 }
3180
3181 /*
3182 ** Repeat for the 'Device List'
3183 */
3184 ptr_tempDevDb = (T_MFW_BT_REM_DEVICE_INFO *)mfwAlloc(data->srch_bt_device_count * sizeof(T_MFW_BT_REM_DEVICE_INFO));
3185 if (ptr_tempDevDb!= (T_MFW_BT_REM_DEVICE_INFO *)0)
3186 {
3187 /*
3188 ** Copy the list of devices
3189 */
3190 memcpy(ptr_tempDevDb, data->srch_bt_dev_list, (data->srch_bt_device_count * sizeof(T_MFW_BT_REM_DEVICE_INFO)));
3191
3192 /*
3193 ** Free the first (and larger) list
3194 */
3195 mfwFree((U8 *)data->srch_bt_dev_list, (U16)(data->srch_bt_num_devices * sizeof(T_MFW_BT_REM_DEVICE_INFO)));
3196
3197 data->srch_bt_dev_list = ptr_tempDevDb;
3198 }
3199
3200 /*
3201 ** Configure some other List parameters
3202 */
3203 data->srch_bt_num_devices = data->srch_bt_device_count;
3204 data->srch_bt_list_devices_menu_data.ListLength = data->srch_bt_device_count;
3205
3206 data->srch_bt_list_devices_menu_data.Attr->nItems = data->srch_bt_device_count;
3207
3208 data->srch_bt_list_devices_menu_data.Attr->hdrId = TxtBtDevices;
3209 data->srch_bt_list_devices_menu_data.LeftSoftKey = TxtSoftOptions;
3210 data->srch_bt_list_devices_menu_data.RightSoftKey = TxtSoftBack;
3211
3212 /*
3213 ** CQ21842 : Modify the List Key Events so that it handles all teh keys it requires.
3214 */
3215 data->srch_bt_list_devices_menu_data.KeyEvents = KEY_CLEAR | KEY_RIGHT | KEY_LEFT | KEY_MNUUP | KEY_MNUDOWN |KEY_HUP;
3216
3217 data->srch_bt_list_devices_menu_data.autoDestroy = TRUE;
3218
3219 data->srch_bt_dev_list_cb = (ListCbFunc)bt_srch_dev_list_listmnu_cb;
3220
3221 /*
3222 ** CQ21841 : For each device in the list, reset the string pointer because it will be pointing to the old device
3223 ** list which has just been freed
3224 */
3225 for (iLoop = 0; iLoop < data->srch_bt_num_devices; iLoop++)
3226 data->srch_bt_list_devices_menu_data.List[iLoop].str = data->srch_bt_dev_list[iLoop].name;
3227
3228 /*
3229 ** Recreate the menu with the new details;
3230 */
3231 if (listDisplayListMenu(data->win, &data->srch_bt_list_devices_menu_data, data->srch_bt_dev_list_cb, FALSE) != LISTS_FAIL)
3232 data->srch_bt_dev_list_win = data->srch_bt_list_devices_menu_data.win;
3233 }
3234 }
3235 }
3236
3237 break;
3238
3239 case BT_PAIR_DEVICE:
3240 #ifdef NEW_EDITOR
3241 /*
3242 ** Initialise the editor
3243 */
3244 AUI_edit_SetDefault(&editor_data);
3245 AUI_edit_SetMode(&editor_data, ED_MODE_HIDDEN, ED_CURSOR_BAR);
3246
3247 AUI_edit_SetBuffer(&editor_data, ATB_DCS_ASCII, data->bt_pairing_pin_buf, MFW_BT_MAX_PIN_CODE_LEN);
3248 AUI_edit_SetTextStr(&editor_data, TxtSoftSelect, TxtSoftBack, TxtBtEnterPassKey, TxtNull);
3249 AUI_edit_SetAltTextStr(&editor_data, 1, TxtNull, TRUE, TxtCancel);
3250
3251 AUI_edit_SetEvents(&editor_data, BT_PAIRING_EDITOR, TRUE, FOREVER, (T_AUI_EDIT_CB)mmi_bluetooth_editor_cb);
3252
3253 data->srch_bt_pairing_pin_editor= AUI_edit_Start(data->win, &editor_data);
3254 #endif
3255 break;
3256
3257 case BT_SHOW_DEV_SERVICES:
3258
3259 cur_device = &data->srch_bt_dev_list[data->srch_bt_cur_dev_idx];
3260
3261 data->srch_bt_please_wait_dialog = mmi_bluetooth_show_please_wait(data->win);
3262
3263 mfw_bt_dm_discover_device(cur_device->bd_addr);
3264
3265 break;
3266
3267 case BT_DISABLE_SEARCH:
3268 mmi_bt_search_destroy();
3269 break;
3270
3271 default:
3272 MFW_BT_TRACE("mmi_bluetooth() : Unexpected Event!");
3273 }
3274
3275 return;
3276 }
3277
3278
3279 /*******************************************************************************
3280
3281 $Function: mmi_bluetooth_win_cb
3282
3283 $Description: This function is the windows callback function for the Bluetooth Root window.
3284 It has no display
3285
3286 $Returns: MFW_EVENT_REJECTED : This window does not display anything. The event is rejected
3287 so it is passed down the win chain.
3288
3289 $Arguments: Not used.
3290
3291 *******************************************************************************/
3292 int mmi_bluetooth_win_cb (MfwEvt evt, MfwHnd win)
3293 {
3294 MFW_BT_TRACE("mmi_bluetooth_win_cb()");
3295
3296 return MFW_EVENT_REJECTED;
3297 }
3298
3299 /*******************************************************************************
3300
3301 $Function: mmi_bluetooth_device_mnu_cb
3302
3303 $Description: This function is called when the user has a list of devices (either known or local)
3304 and they select 1.
3305
3306 $Returns: BOOL - True is successful, otherwise FALSE
3307
3308 $Arguments: None
3309
3310 *******************************************************************************/
3311 static int mmi_bluetooth_device_mnu_cb(MfwMnu * mnu, MfwMnuItem * item)
3312 {
3313 MFW_BT_TRACE("mmi_bluetooth_device_mnu_cb()");
3314
3315 bt_srch_data.srch_bt_cur_dev_idx = mnu->lCursor[mnu->level];
3316
3317 /*
3318 ** CQ22023 : Modify the Menu Header to display the name of the Current Device
3319 */
3320 menuBtDeviceOptions.hdrId = (int)bt_srch_data.srch_bt_dev_list[bt_srch_data.srch_bt_cur_dev_idx].name;
3321 }
3322
3323 /*******************************************************************************
3324
3325 $Function: mmi_bluetooth_editor_cb
3326
3327 $Description: This function provides the callback functionality to an editor for Bluetooth
3328
3329 $Returns: None
3330
3331 $Arguments:
3332
3333 *******************************************************************************/
3334
3335 static void mmi_bluetooth_editor_cb(T_MFW_HND win, USHORT identifier, SHORT reason)
3336 {
3337 T_MFW_WIN * win_data = ((T_MFW_HDR *) win)->data;
3338 T_MMI_BT_PIN_Req_Data * pin_req_data = (T_MMI_BT_PIN_Req_Data *)win_data->user;
3339 T_MMI_BT_Dev_Name_Data* dev_name_data = (T_MMI_BT_Dev_Name_Data *)win_data->user;
3340 T_MMI_BtSearchData *srch_data = (T_MMI_BtSearchData *)win_data->user;
3341
3342 UBYTE * editor_buffer = NULL;
3343 SHORT max_edit_size = 0;
3344 T_MFW_HND editor_win;
3345 T_MFW_HND parent;
3346
3347 MFW_BT_TRACE("mmi_bluetooth_editor_cb()");
3348
3349 if ((identifier == BT_DEV_NAME_EDITOR) ||
3350 (identifier == BT_REM_DEV_NAME_EDITOR)) /* CQ21843 */
3351 {
3352 editor_buffer = dev_name_data->bt_device_name;
3353 max_edit_size = MFW_BT_NAME_LENGTH;
3354 editor_win = dev_name_data->bt_dev_name_editor;
3355 parent = dev_name_data->win;
3356 }
3357 else if (identifier == BT_PIN_REQ_EDITOR)
3358 {
3359 editor_buffer = pin_req_data->bt_pin_req_buf;
3360 max_edit_size = MFW_BT_MAX_PIN_CODE_LEN;
3361 editor_win = pin_req_data->bt_pin_req_editor;
3362 parent = pin_req_data->win;
3363 }
3364 else if (identifier == BT_PAIRING_EDITOR)
3365 {
3366 editor_buffer = srch_data->bt_pairing_pin_buf;
3367 max_edit_size = MFW_BT_MAX_PIN_CODE_LEN;
3368 editor_win = srch_data->srch_bt_pairing_pin_editor;
3369 parent = srch_data->win;
3370 }
3371 else
3372 {
3373 MFW_BT_TRACE_P1("mmi_bluetooth_editor_cb() : Unknown Identifier %d", identifier);
3374 /*
3375 ** if this isn't one of the "recognised" editors leave now!
3376 */
3377 return;
3378 }
3379
3380 switch (reason)
3381 {
3382 case INFO_KCD_LEFT:
3383 {
3384 /*
3385 ** Construct the required string
3386 */
3387
3388 /*
3389 ** The Editor Attributes for all Bluetooth Editors require ASCII text. Text should not be Unicode
3390 **
3391 if (editor_buffer[0] == 0x80 ) // If Unicode (there is no way it should be though!!)
3392 { //If empty string, remove 0x80 at beginning
3393 if (editor_buffer[2]==0x00 && editor_buffer[3] == 0x00)
3394 memset(editor_buffer, 0, max_edit_size);
3395 }
3396 */
3397
3398 /*
3399 ** If there is no string entered, treat this as if it was a "Cancel"
3400 */
3401 if (editor_buffer[0] == 0x00)
3402 {
3403 /*
3404 ** Send a "Cancel" to the Bluetooth window
3405 */
3406 SEND_EVENT(parent, BT_EDITOR_CANCEL, identifier, NULL);
3407 }
3408 else
3409 {
3410 /*
3411 ** Send a "Select" to the Bluetooth window
3412 */
3413 SEND_EVENT(parent, BT_EDITOR_SELECT, identifier, NULL);
3414 }
3415 }
3416 break;
3417
3418 case INFO_KCD_RIGHT:
3419 if (strlen((char *)editor_buffer) == 0)
3420 {
3421 /*
3422 ** Send a "Cancel" to the Bluetooth window
3423 */
3424 SEND_EVENT(parent, BT_EDITOR_CANCEL, identifier, NULL);
3425 }
3426 break;
3427
3428 case INFO_KCD_HUP:
3429 /*
3430 ** Set the buffer to NULLS
3431 */
3432 memset(editor_buffer, 0x00, max_edit_size);
3433
3434
3435 /*
3436 ** Send a "Cancel" to the Bluetooth window
3437 */
3438 SEND_EVENT(parent, BT_EDITOR_CANCEL, identifier, NULL);
3439 break;
3440
3441 default:
3442 /* otherwise no action to be performed
3443 */
3444 break;
3445 }
3446 }
3447
3448 /*******************************************************************************
3449
3450 $Function: mmi_bluetooth_search_cb
3451
3452 $Description: This function
3453
3454 $Returns: None
3455
3456 $Arguments:
3457
3458 *******************************************************************************/
3459
3460 static int mmi_bluetooth_search_cb(T_MFW_EVENT evnt, void *para)
3461 {
3462 MFW_BT_TRACE_P1("mmi_bluetooth_search_cb() : event received %d", evnt);
3463
3464 switch (evnt)
3465 {
3466 case E_BT_DM_AUTH_CMPL:
3467 if (bt_srch_data.srch_bt_req_resp == BT_PAIRED_NOT_RESP)
3468 SEND_EVENT(bt_srch_data.win, BT_AUTH_COMPLETE, 0, (void *)para);
3469 else
3470 return MFW_EVENT_REJECTED;
3471 break;
3472
3473 case E_BT_DM_INQ_CMPL:
3474 SEND_EVENT(bt_srch_data.win, BT_INQUIRY_COMPLETE, 0, (void *)para);
3475 break;
3476
3477 case E_BT_DM_DISC_RES:
3478 SEND_EVENT(bt_srch_data.win, BT_DISCOVER_RESULT, 0, (void *)para);
3479 break;
3480
3481 case E_BT_DM_DISC_CMPL:
3482 SEND_EVENT(bt_srch_data.win, BT_DISCOVER_COMPLETE, 0, (void *)para);
3483 break;
3484
3485 default:
3486 return MFW_EVENT_REJECTED;
3487 }
3488
3489 return MFW_EVENT_CONSUMED;
3490 }
3491 /*******************************************************************************
3492
3493 $Function: mmi_bluetooth_root_cb
3494
3495 $Description: This function
3496
3497 $Returns: None
3498
3499 $Arguments:
3500
3501 *******************************************************************************/
3502
3503 static int mmi_bluetooth_root_cb(T_MFW_EVENT evnt, void* para)
3504 {
3505 T_MFW_BT_STATUS btRetVal;
3506 T_MMI_BtData *data = &bt_data;
3507 T_MFW_HND win = mfw_parent(mfw_header());
3508
3509 MFW_BT_TRACE_P1("mmi_bluetooth_root_cb() : event received %d", evnt);
3510
3511 switch (evnt)
3512 {
3513 case E_BT_ENABLE_CMPL:
3514 if (((T_MFW_BT_ENABLE_CMPL *)para)->Success == FALSE)
3515 {
3516 /*
3517 ** Ensure Flag is Disabled
3518 */
3519 data->bt_isActive = FALSE;
3520
3521 /*
3522 ** Turn the Bluetooth Icon Off ... Not Done because there is no documentation re icons!!!!!
3523 ** and there is not the time to figure them out from Raw Code!!
3524 */
3525
3526 /*
3527 ** Create a timed dialog to display the Message "Bluetooth Failed"
3528 */
3529 mmi_bluetooth_show_info(0, TxtBluetooth, TxtFailed);
3530 }
3531 else
3532 {
3533 /*
3534 ** Set Flag to Enabled
3535 */
3536 data->bt_isActive = TRUE;
3537
3538 /*
3539 ** Turn the Bluetooth Icon On ... Not Done because there is no documentation re icons!!!!!
3540 ** and there is not the time to figure them out from Raw Code!!
3541 */
3542
3543 /*
3544 ** Create a timed dialog to display the Message "Bluetooth Activated"
3545 */
3546 mmi_bluetooth_show_info(0, TxtBluetooth, TxtActivated);
3547 }
3548 break;
3549
3550 case E_BT_DISABLE_CMPL:
3551 /*
3552 ** Set Flag to Enabled
3553 */
3554 data->bt_isActive = FALSE;
3555
3556 /*
3557 ** Turn the Bluetooth Icon Off ... Not Done because there is no documentation re icons!!!!!
3558 ** and there is not the time to figure them out from Raw Code!!
3559 */
3560
3561 /*
3562 ** Create a timed dialog to display the Message "Bluetooth DeActivated"
3563 */
3564 mmi_bluetooth_show_info(0, TxtBluetooth, TxtDeActivated);
3565 break;
3566
3567 case E_BT_DM_DEV_NAME_REQ:
3568 if (data->bt_dev_name_win == (void *)0)
3569 {
3570 data->bt_DevNameForStartup = TRUE;
3571 data->bt_dev_name_win = mmi_bt_dev_name_create(win);
3572
3573 if (data->bt_dev_name_win != (void *)0)
3574 {
3575 SEND_EVENT(data->bt_dev_name_win, BT_DEV_NAME_REQ, 0, (void *)para);
3576 }
3577 else
3578 {
3579 MFW_BT_TRACE("mmi_bluetooth_root_cb() : Unable to create Device Name Win!");
3580
3581 btRetVal = mfw_bt_dm_set_local_name((void *)0);
3582 if (btRetVal != MFW_BT_SUCCESS)
3583 {
3584 MFW_BT_TRACE("mmi_bluetooth_root_cb() : Unable to return Device Name to Mfw!");
3585 }
3586 }
3587 }
3588 else
3589 {
3590 MFW_BT_TRACE("mmi_bluetooth_root_cb() : Device Name Win already active");
3591 }
3592 break;
3593
3594 case E_BT_DM_LINK_UP:
3595 if (data->bt_num_active_connections < MFW_BT_MAX_CONSEC_CONNECTIONS)
3596 data->bt_num_active_connections++;
3597 else
3598 {
3599 MFW_BT_TRACE("mmi_bluetooth_root_cb() : LINK_UP indicated after Max Consecutive connections reached");
3600 }
3601 break;
3602
3603 case E_BT_DM_LINK_DOWN:
3604 if (data->bt_num_active_connections >= 1)
3605 data->bt_num_active_connections--;
3606 else
3607 {
3608 MFW_BT_TRACE("mmi_bluetooth_root_cb() : LINK_DOWN indicated when no active connections!");
3609 }
3610 break;
3611
3612 case E_BT_DM_PIN_REQ:
3613 if (data->bt_pin_req_win == (void *)0)
3614 {
3615 data->bt_pin_req_win = mmi_bt_pin_request_create(win);
3616
3617 if (data->bt_pin_req_win != (void *)0)
3618 {
3619 SEND_EVENT(data->bt_pin_req_win, BT_PIN_REQ, 0, (void *)para);
3620 }
3621 else
3622 {
3623 MFW_BT_TRACE("mmi_bluetooth_root_cb() : Unable to create PIN Req Win!");
3624
3625 btRetVal = mfw_bt_dm_pin_code((UINT8 *)0, (UINT8)0);
3626 if (btRetVal != MFW_BT_SUCCESS)
3627 {
3628 MFW_BT_TRACE("mmi_bluetooth_root_cb() : Unable to return PIN to Mfw!");
3629 }
3630 }
3631 }
3632 else
3633 {
3634 MFW_BT_TRACE("mmi_bluetooth_root_cb() : PIN Req Win already active");
3635
3636 btRetVal = mfw_bt_dm_pin_code((UINT8 *)0, (UINT8)0);
3637 if (btRetVal != MFW_BT_SUCCESS)
3638 {
3639 MFW_BT_TRACE("mmi_bluetooth_root_cb() : Unable to return PIN to Mfw!");
3640 }
3641 }
3642 break;
3643
3644 case E_BT_DM_AUTH_CMPL:
3645 if (data->bt_pin_req_win != (void *)0)
3646 {
3647 SEND_EVENT(data->bt_pin_req_win, BT_AUTH_COMPLETE, 0, (void *)para);
3648 }
3649 else
3650 {
3651 MFW_BT_TRACE("mmi_bluetooth_root_cb() : PIN Req Win inactive!");
3652 }
3653 break;
3654
3655 case E_BT_DM_AUTHORIZE_REQ:
3656 if (data->bt_authorize_win == (void *)0)
3657 {
3658 data->bt_authorize_win = mmi_bt_authorize_create(win);
3659
3660 if (data->bt_authorize_win != (void *)0)
3661 {
3662 SEND_EVENT(data->bt_authorize_win, BT_AUTHORIZE_REQ, 0, (void *)para);
3663 }
3664 else
3665 {
3666 MFW_BT_TRACE("mmi_bluetooth_root_cb() : Unable to create Authorization Req Win!");
3667
3668 btRetVal = mfw_bt_dm_authorize_resp(MFW_BT_AUTH_FAIL);
3669 if (btRetVal != MFW_BT_SUCCESS)
3670 {
3671 MFW_BT_TRACE("mmi_bluetooth_root_cb() : Unable to return Authorization to Mfw!");
3672 }
3673 }
3674 }
3675 else
3676 {
3677 MFW_BT_TRACE("mmi_bluetooth_root_cb() : Authorization IReq Win already active");
3678
3679 btRetVal = mfw_bt_dm_authorize_resp(MFW_BT_AUTH_FAIL);
3680 if (btRetVal != MFW_BT_SUCCESS)
3681 {
3682 MFW_BT_TRACE("mmi_bluetooth_root_cb() : Unable to return Authorization to Mfw!");
3683 }
3684 }
3685 break;
3686
3687 case E_BT_DM_SIG_STRENGTH_IND:
3688 break;
3689
3690 case E_BT_DM_INQ_RES:
3691 case E_BT_DM_INQ_CMPL:
3692 case E_BT_DM_DISC_RES:
3693 case E_BT_DM_DISC_CMPL:
3694 default:
3695 MFW_BT_TRACE("mmi_bluetooth_root_cb() : Unexpected Event!!");
3696 }
3697 return MFW_EVENT_CONSUMED;
3698
3699 }
3700
3701 static int mmi_bluetooth_search_timer_cb(MfwEvt e, MfwTim *t)
3702 {
3703 T_MMI_BtSearchData *data = &bt_srch_data;
3704
3705 MFW_BT_TRACE("mmi_bluetooth_search_timer_cb()");
3706
3707 if (data->srch_bt_please_wait_dialog != (void *)0)
3708 {
3709 SEND_EVENT(data->srch_bt_please_wait_dialog, DIALOG_DESTROY, 0, 0);
3710 data->srch_bt_please_wait_dialog = (void *)0;
3711 }
3712 /*
3713 ** Display "No Devices Found" and exit the Search Window
3714 */
3715 mmi_bluetooth_show_info_callback(data->win, TxtBtNoDevices, TxtBtFound, mmi_bt_srch_no_device_found_dlg_cb);
3716
3717 data->srch_bt_mode = BT_MODE_NO_SEARCH;
3718 }
3719 static int mmi_bluetooth_discovery_timer_cb(MfwEvt e, MfwTim *t)
3720 {
3721 T_MMI_BtData *data = &bt_data;
3722 T_MFW_BT_STATUS btRetVal;
3723
3724 MFW_BT_TRACE("mmi_bluetooth_discovery_timer_cb()");
3725
3726 /*
3727 ** Make the Device Not Discoverable, (Device Hiddenm but from Temporary Request)
3728 */
3729 btRetVal = mfw_bt_dm_set_visibility(FALSE, TRUE);
3730
3731 if (btRetVal != MFW_BT_SUCCESS)
3732 {
3733 MFW_BT_TRACE_P1("mmi_bluetooth_discovery_timer_cb() : Set Visibility (FALSE) failed with status : %d", btRetVal);
3734 }
3735 else
3736 {
3737 /*
3738 ** Create a timed dialog to display the Message "Device Hidden"
3739 */
3740 mmi_bluetooth_show_info(0, TxtBtDevice, TxtBtHidden);
3741 }
3742
3743 if (data->bt_stopBtOnDiscoverableTimeout != FALSE)
3744 {
3745 /*
3746 ** If there are currently active connections, start the connection timer, otherwise turn bluetooth off
3747 */
3748 if (data->bt_num_active_connections >= 1)
3749 {
3750 timStart(data->bt_connection_timer);
3751 }
3752 else if (data->bt_isActive != FALSE)
3753 {
3754 /*
3755 ** Disable the Bluetooth module
3756 */
3757 mfw_bt_disable();
3758 }
3759 }
3760 }
3761
3762 static int mmi_bluetooth_connection_timer_cb(MfwEvt e, MfwTim *t)
3763 {
3764 T_MMI_BtData *data = &bt_data;
3765
3766 MFW_BT_TRACE("mmi_bluetooth_connection_timer_cb()");
3767
3768 /*
3769 ** If there are currently active connections, start the connection timer, otherwise turn bluetooth off
3770 */
3771 if (data->bt_num_active_connections >= 1)
3772 {
3773 timStart(data->bt_connection_timer);
3774 }
3775 else if (data->bt_isActive != FALSE)
3776 {
3777 /*
3778 ** Disable the Bluetooth module
3779 */
3780 mfw_bt_disable();
3781 }
3782 }
3783
3784 static void mmi_bluetooth_dlg_cb(void)
3785 {
3786 MFW_BT_TRACE("mmi_bluetooth_dlg_cb()");
3787
3788 return;
3789 }
3790
3791 static void mmi_bt_srch_no_device_found_dlg_cb(void)
3792 {
3793 MFW_BT_TRACE("mmi_bt_srch_no_device_found_dlg_cb()");
3794
3795 mmi_bt_search_destroy();
3796 return;
3797 }
3798 static MfwHnd mmi_bluetooth_show_please_wait(T_MFW_HND parent)
3799 {
3800 T_DISPLAY_DATA display_info;
3801
3802 MFW_BT_TRACE("mmi_bluetooth_show_please_wait()");
3803
3804 /*
3805 ** Create a timed dialog to display the Message "Failed"
3806 */
3807 dlg_initDisplayData_TextId( &display_info, TxtNull, TxtNull, TxtPleaseWait, TxtNull, COLOUR_STATUS);
3808 dlg_initDisplayData_events( &display_info, mmi_bluetooth_dlg_cb, FOREVER, 0);
3809
3810 return info_dialog(parent, &display_info);
3811 }
3812
3813 static MfwHnd mmi_bluetooth_show_info_callback(T_MFW_HND parent, int str1, int str2, T_VOID_FUNC callback)
3814 {
3815 T_DISPLAY_DATA display_info;
3816
3817 MFW_BT_TRACE("mmi_bluetooth_show_info()");
3818
3819
3820 /*
3821 ** Create a timed dialog to display the Message "Failed"
3822 */
3823 dlg_initDisplayData_TextId( &display_info, TxtNull, TxtNull, str1, str2, COLOUR_STATUS);
3824 dlg_initDisplayData_events( &display_info, callback, BT_INFO_SCRN_TIMEOUT, KEY_LEFT | KEY_CLEAR | KEY_HUP);
3825
3826 return info_dialog(parent, &display_info);
3827 }
3828
3829 static MfwHnd mmi_bluetooth_show_info(T_MFW_HND parent, int str1, int str2)
3830 {
3831 return mmi_bluetooth_show_info_callback(parent, str1, str2, mmi_bluetooth_dlg_cb);
3832 }
3833
3834
3835
3836 T_MFW_HND bt_menu_start(MfwHnd parent, MfwMnuAttr* menuAttr, T_VOID_FUNC cancel_cb)
3837 {
3838 T_MFW_HND win;
3839 T_MFW_WIN *win_data;
3840 T_bt_menu *data;
3841
3842 MFW_BT_TRACE("bt_menu_start()");
3843
3844 win = bt_menu_create (parent);
3845
3846 if (win NEQ NULL)
3847 {
3848 win_data = ((T_MFW_HDR *)win)->data;
3849 data = (T_bt_menu *)win_data->user;
3850
3851 data->cancel_cb = cancel_cb;
3852
3853 SEND_EVENT (win, BT_MNU_INIT, 0, (MfwMnuAttr*) menuAttr);
3854 }
3855
3856 return win;
3857 }
3858
3859 static T_MFW_HND bt_menu_create(MfwHnd parent)
3860 {
3861 T_MFW_WIN * win_data;
3862 T_bt_menu * data = (T_bt_menu *)mfwAlloc(sizeof (T_bt_menu));
3863
3864
3865 MFW_BT_TRACE ("bt_menu_create()");
3866
3867 data->win = win_create (parent, 0, E_WIN_VISIBLE, (T_MFW_CB)bt_menu_win_cb);
3868
3869 if (data->win EQ 0)
3870 return 0;
3871
3872 /*
3873 * Create window handler
3874 */
3875 data->mmi_control.dialog = (T_DIALOG_FUNC)bt_menu;
3876 data->mmi_control.data = data;
3877 win_data = ((T_MFW_HDR *)data->win)->data;
3878 win_data->user = (void *)data;
3879
3880 /*
3881 ** Create the keyboard Handler
3882 */
3883 data->kbd = kbdCreate(data->win,KEY_ALL,(MfwCb)bt_menu_kbd_cb);
3884 data->kbd_long = kbdCreate(data->win,KEY_ALL|KEY_LONG,(MfwCb)bt_menu_kbd_long_cb);
3885
3886 /*
3887 * return window handle
3888 */
3889 return data->win;
3890 }
3891
3892 static void bt_menu_destroy(MfwHnd window)
3893 {
3894 T_MFW_WIN * win_data = ((T_MFW_HDR *)window)->data;
3895 T_bt_menu * data = (T_bt_menu *)win_data->user;
3896
3897 MfwHnd auth_win = bt_data.bt_authorize_win;
3898 T_MFW_WIN * auth_win_data = ((T_MFW_HDR *) auth_win)->data;
3899 T_MMI_BT_Authorise_Data * auth_data = (T_MMI_BT_Authorise_Data *)auth_win_data->user;
3900
3901 MFW_BT_TRACE ("bt_menu_destroy()");
3902
3903 if (window == NULL)
3904 {
3905 MFW_BT_TRACE ("Error : Called with NULL Pointer");
3906 return;
3907 }
3908
3909 if (data)
3910 {
3911 auth_data->bt_auth_menu = 0;
3912 winDelete (data->win);
3913
3914 /*
3915 ** Free Memory
3916 */
3917 mfwFree((void *)data, sizeof (T_bt_menu));
3918 }
3919 }
3920
3921 static void bt_menu (T_MFW_HND win, USHORT event, SHORT value, void * parameter)
3922 {
3923 T_MFW_WIN * win_data = ((T_MFW_HDR *) win)->data;
3924 T_bt_menu * data = (T_bt_menu *)win_data->user;
3925
3926 MFW_BT_TRACE ("bt_menu()");
3927
3928 switch (event)
3929 {
3930 case BT_MNU_INIT:
3931 data->menu = mnuCreate(data->win, (MfwMnuAttr*)parameter, E_MNU_ESCAPE, (MfwCb)bt_menu_mnu_cb);
3932 mnuLang(data->menu, mainMmiLng);
3933 mnuUnhide(data->menu);
3934 winShow(data->win);
3935 break;
3936
3937 default:
3938 return;
3939 }
3940 }
3941
3942 static int bt_menu_mnu_cb (MfwEvt e, MfwMnu *m)
3943 {
3944 T_MFW_HND win = mfwParent(mfw_header());
3945
3946 MfwHnd auth_win = bt_data.bt_authorize_win;
3947 T_MFW_WIN * win_data = ((T_MFW_HDR *) auth_win)->data;
3948 T_MMI_BT_Authorise_Data * data = (T_MMI_BT_Authorise_Data *)win_data->user;
3949
3950 MFW_BT_TRACE ("bt_menu_mnu_cb()");
3951
3952 switch (e)
3953 {
3954 case E_MNU_ESCAPE:
3955 bt_menu_destroy(win);
3956 data->bt_auth_menu = 0;
3957 break;
3958
3959 default:
3960 return 0;
3961 }
3962
3963 return 1;
3964 }
3965
3966 static int bt_menu_win_cb (MfwEvt e, MfwWin *w)
3967 {
3968 T_bt_menu * data = (T_bt_menu *)w->user;
3969 MfwMnu * mnu;
3970
3971 MFW_BT_TRACE ("bt_menu_win_cb()");
3972
3973 switch (e)
3974 {
3975 case MfwWinVisible:
3976 mnu = (MfwMnu *)mfwControl(data->menu);
3977 softKeys_displayId(TxtSoftSelect, TxtSoftBack, 0, mnu->curAttr->mnuColour );
3978 break;
3979
3980 default:
3981 return 0;
3982 }
3983 return 1;
3984 }
3985
3986 static int bt_menu_kbd_cb (MfwEvt e, MfwKbd *k)
3987 {
3988 T_MFW_HND win = mfwParent(mfw_header());
3989 T_MFW_WIN *win_data = ((T_MFW_HDR *)win)->data;
3990 T_bt_menu *data = (T_bt_menu *)win_data->user;
3991
3992 T_VOID_FUNC cancel_cb;
3993
3994 MFW_BT_TRACE ("bt_menu_kbd_cb()");
3995
3996
3997 switch (k->code)
3998 {
3999 case KCD_MNUUP:
4000 mnuUp(data->menu);
4001 winShow(win);
4002 break;
4003
4004 case KCD_MNUDOWN:
4005 mnuDown(data->menu);
4006 winShow(win);
4007 break;
4008
4009 case KCD_LEFT:
4010 mnuSelect(data->menu);
4011 {
4012 MfwMnu *mnu;
4013 mnu = (MfwMnu *) mfwControl( data->menu );
4014 if (mnu != NULL)
4015 {
4016 if (mnu->curAttr != NULL)
4017 softKeys_displayId( TxtSoftSelect, TxtSoftBack, 0, mnu->curAttr->mnuColour);
4018 }
4019 }
4020 break;
4021
4022 case KCD_RIGHT:
4023 case KCD_HUP:
4024 cancel_cb = data->cancel_cb;
4025 mnuEscape(data->menu);
4026
4027 cancel_cb();
4028 break;
4029
4030 default:
4031 return MFW_EVENT_CONSUMED;
4032 }
4033 return MFW_EVENT_CONSUMED;
4034 }
4035
4036 static int bt_menu_kbd_long_cb (MfwEvt e, MfwKbd *k)
4037 {
4038 T_MFW_HND win = mfwParent(mfw_header());
4039 T_MFW_WIN * win_data = ((T_MFW_HDR *)win)->data;
4040 T_bt_menu * data = (T_bt_menu *)win_data->user;
4041
4042
4043 MFW_BT_TRACE ("bt_menu_kbd_long_cb()");
4044
4045 if ((e & KEY_CLEAR) && (e & KEY_LONG))
4046 {
4047 mnuEscape(data->menu);
4048 return MFW_EVENT_CONSUMED;
4049 }
4050
4051 return MFW_EVENT_CONSUMED;
4052 }
4053
4054 static void mmi_bt_authorize_editor_cb(T_MFW_HND win, USHORT identifier, SHORT reason)
4055 {
4056 MfwHnd auth_win = bt_data.bt_authorize_win;
4057 T_MFW_WIN * win_data = ((T_MFW_HDR *) auth_win)->data;
4058 T_MMI_BT_Authorise_Data * data = (T_MMI_BT_Authorise_Data *)win_data->user;
4059
4060 MFW_BT_TRACE("bt_auth_editor_cb()");
4061
4062 switch (reason)
4063 {
4064 case INFO_KCD_RIGHT:
4065 case INFO_KCD_HUP:
4066 /*
4067 ** CQ22021 : The Editor is destroyed automatically, reset the win value to NULL
4068 */
4069 data->bt_auth_info_editor = (void *)0;
4070
4071 /*
4072 ** Free the dynamically allocated memory
4073 */
4074 mfwFree(data->bt_auth_info_text, data->bt_auth_info_text_size);
4075 break;
4076
4077 default:
4078 /* otherwise no action to be performed
4079 */
4080 break;
4081 }
4082
4083 return;
4084 }
4085
4086 static int mmi_bt_authorize_display_info(MfwMnu* m, MfwMnuItem* i)
4087 {
4088 T_MFW_HND auth_win = bt_data.bt_authorize_win;
4089 T_MFW_WIN * win_data = ((T_MFW_HDR *) auth_win)->data;
4090 T_MMI_BT_Authorise_Data * data = (T_MMI_BT_Authorise_Data *)win_data->user;
4091
4092 USHORT reqBufSize = 0;
4093 USHORT serviceTxtId = TxtNotSupported;
4094 #ifdef NEW_EDITOR
4095 T_AUI_EDITOR_DATA editor_data;
4096 #endif
4097
4098 MFW_BT_TRACE("mmi_bt_authorize_display_info()");
4099
4100 /*
4101 ** Get the Text Id to be used to represent the service
4102 */
4103 switch(data->bt_auth_req_param->service)
4104 {
4105 case BTA_SPP_SERVICE_ID:
4106 serviceTxtId = TxtBtSerialPort;
4107 break;
4108
4109 case BTA_DUN_SERVICE_ID:
4110 serviceTxtId = TxtBtDialUpNetworking;
4111 break;
4112
4113 case BTA_FAX_SERVICE_ID:
4114 serviceTxtId = TxtFax;
4115 break;
4116
4117 case BTA_HSP_SERVICE_ID:
4118 serviceTxtId = TxtBtHeadSet;
4119 break;
4120
4121 case BTA_HFP_SERVICE_ID:
4122 serviceTxtId = TxtBtHandsFree;
4123 break;
4124
4125 case BTA_OP_SERVICE_ID:
4126 serviceTxtId = TxtBtObjectPush;
4127 break;
4128
4129 case BTA_FT_SERVICE_ID:
4130 serviceTxtId = TxtBtFileTransfer;
4131 break;
4132 }
4133
4134 /*
4135 ** Calculate the size of Buffer required this will give a little extra ... not not much.
4136 */
4137 reqBufSize = BT_MAX_DISPLAY_DEV_NAME_LENGTH; // The max length of the dev name was ensured when the event was received
4138 reqBufSize += strlen(MmiRsrcGetText(TxtBtRequiresAuthorizationForService));
4139 reqBufSize += strlen(MmiRsrcGetText(serviceTxtId));
4140 reqBufSize += 6; // Added for CR/Lf to ensure enough space
4141
4142 /*
4143 ** Allocate enough memory for the display text
4144 */
4145 data->bt_auth_info_text = mfwAlloc(reqBufSize);
4146
4147 if (data->bt_auth_info_text == 0)
4148 {
4149 /*
4150 ** Display an error dialog and return
4151 */
4152 mmi_bluetooth_show_info(data->win, TxtFailed, TxtErrorOutOfMem);
4153 return MFW_EVENT_CONSUMED;
4154 }
4155
4156 data->bt_auth_info_text_size = reqBufSize;
4157
4158 sprintf((char *)data->bt_auth_info_text, MmiRsrcGetText(TxtBtRequiresAuthorizationForService),
4159 (char *)data->bt_auth_req_param->bd_name,
4160 (char *)MmiRsrcGetText(serviceTxtId));
4161
4162 #ifdef NEW_EDITOR
4163 /*
4164 ** Initialise the editor
4165 */
4166 AUI_edit_SetDefault(&editor_data);
4167
4168 AUI_edit_SetBuffer(&editor_data, ATB_DCS_ASCII, data->bt_auth_info_text, data->bt_auth_info_text_size);
4169 AUI_edit_SetTextStr(&editor_data, TxtNull, TxtSoftBack, TxtBtInfo, TxtNull);
4170 AUI_edit_SetMode(&editor_data, ED_MODE_READONLY, ED_CURSOR_NONE);
4171
4172 AUI_edit_SetEvents(&editor_data, 0, TRUE, FOREVER, mmi_bt_authorize_editor_cb);
4173
4174 data->bt_auth_info_editor = AUI_edit_Start(data->win, &editor_data);
4175 #endif
4176
4177 return MFW_EVENT_CONSUMED;
4178 }
4179
4180 static int mmi_bt_authorize_once(MfwMnu* m, MfwMnuItem* i)
4181 {
4182 MfwHnd auth_win = bt_data.bt_authorize_win;
4183 T_MFW_WIN * win_data = ((T_MFW_HDR *) auth_win)->data;
4184 T_MMI_BT_Authorise_Data * data = (T_MMI_BT_Authorise_Data *)win_data->user;
4185 T_MFW_BT_STATUS btRetVal;
4186
4187 MFW_BT_TRACE("mmi_bt_authorize_once()");
4188
4189 /*
4190 ** Send the appropriate response to Bluetooth
4191 */
4192 btRetVal = mfw_bt_dm_authorize_resp(MFW_BT_AUTH_ONCE);
4193
4194 /*
4195 ** Destroy the Menu
4196 */
4197 if (data->bt_auth_menu != 0)
4198 bt_menu_destroy(data->bt_auth_menu);
4199
4200 /*
4201 ** Free the Allocated Memory
4202 */
4203 mfwFree((U8 *)data->bt_auth_req_param, (U16)sizeof(T_MFW_BT_DM_AUTHORIZE_REQ));
4204 data->bt_auth_req_param = (void *)0;
4205
4206 /*
4207 ** Destroy the Authorization Window
4208 */
4209 mmi_bt_authorize_destroy(data->win);
4210
4211 return MFW_EVENT_CONSUMED;
4212
4213 }
4214
4215 static int mmi_bt_authorize_always(MfwMnu* m, MfwMnuItem* i)
4216 {
4217 MfwHnd auth_win = bt_data.bt_authorize_win;
4218 T_MFW_WIN * win_data = ((T_MFW_HDR *) auth_win)->data;
4219 T_MMI_BT_Authorise_Data * data = (T_MMI_BT_Authorise_Data *)win_data->user;
4220 T_MFW_BT_STATUS btRetVal;
4221
4222 MFW_BT_TRACE("bt_authorize_always()");
4223
4224 /*
4225 ** Send the appropriate response to Bluetooth
4226 */
4227 btRetVal = mfw_bt_dm_authorize_resp(MFW_BT_AUTH_ALWAYS);
4228
4229 /*
4230 ** Destroy the Menu
4231 */
4232 if (data->bt_auth_menu != 0)
4233 bt_menu_destroy(data->bt_auth_menu);
4234
4235 /*
4236 ** Free the Allocated Memory
4237 */
4238 mfwFree((U8 *)data->bt_auth_req_param, (U16)sizeof(T_MFW_BT_DM_AUTHORIZE_REQ));
4239 data->bt_auth_req_param = (void *)0;
4240
4241 /*
4242 ** Destroy the Authorization Window
4243 */
4244 mmi_bt_authorize_destroy(data->win);
4245
4246 return MFW_EVENT_CONSUMED;
4247
4248 }
4249
4250 static int mmi_bt_dont_authorize(MfwMnu* m, MfwMnuItem* i)
4251 {
4252 MfwHnd auth_win = bt_data.bt_authorize_win;
4253 T_MFW_WIN * win_data = ((T_MFW_HDR *) auth_win)->data;
4254 T_MMI_BT_Authorise_Data * data = (T_MMI_BT_Authorise_Data *)win_data->user;
4255 T_MFW_BT_STATUS btRetVal;
4256
4257 MFW_BT_TRACE("mmi_bt_dont_authorize()");
4258
4259 /*
4260 ** Send the appropriate response to Bluetooth
4261 */
4262 btRetVal = mfw_bt_dm_authorize_resp(MFW_BT_AUTH_FAIL);
4263
4264 /*
4265 ** Destroy the Menu
4266 */
4267 if (data->bt_auth_menu != 0)
4268 bt_menu_destroy(data->bt_auth_menu);
4269
4270 /*
4271 ** Free the Allocated Memory
4272 */
4273 mfwFree((U8*)data->bt_auth_req_param, (U16)sizeof(T_MFW_BT_DM_AUTHORIZE_REQ));
4274 data->bt_auth_req_param = (void *)0;
4275
4276 /*
4277 ** Destroy the Authorization Window
4278 */
4279 mmi_bt_authorize_destroy(data->win);
4280
4281 return MFW_EVENT_CONSUMED;
4282 }
4283
4284 static void mmi_bt_authorize_rsk(void)
4285 {
4286 MfwHnd auth_win = bt_data.bt_authorize_win;
4287 T_MFW_WIN * win_data = ((T_MFW_HDR *) auth_win)->data;
4288 T_MMI_BT_Authorise_Data * data = (T_MMI_BT_Authorise_Data *)win_data->user;
4289 T_MFW_BT_STATUS btRetVal;
4290
4291 MFW_BT_TRACE("bt_authorize_rsk()");
4292
4293 /*
4294 ** Send the appropriate response to Bluetooth
4295 */
4296 btRetVal = mfw_bt_dm_authorize_resp(MFW_BT_AUTH_FAIL);
4297
4298 /*
4299 ** Destroy the Menu
4300 */
4301 if (data->bt_auth_menu != 0)
4302 bt_menu_destroy(data->bt_auth_menu);
4303
4304 /*
4305 ** Menu will be destroyed automatically by Right Softkey Press
4306 ** Free the Allocated Memory
4307 */
4308 mfwFree((U8 *)data->bt_auth_req_param, (U16)sizeof(T_MFW_BT_DM_AUTHORIZE_REQ));
4309 data->bt_auth_req_param = (void *)0;
4310
4311 /*
4312 ** Destroy the Authorization Window
4313 */
4314 mmi_bt_authorize_destroy(data->win);
4315
4316 return;
4317 }
4318
4319 static int bt_srch_dev_pair (MfwMnu * mnu, MfwMnuItem * item)
4320 {
4321 MFW_BT_TRACE("bt_srch_dev_pair()");
4322
4323 SEND_EVENT(bt_srch_data.win, BT_PAIR_DEVICE, 0, 0);
4324
4325 return MFW_EVENT_CONSUMED;
4326 }
4327
4328 static int bt_srch_dev_show_services (MfwMnu * mnu, MfwMnuItem * item)
4329 {
4330 MFW_BT_TRACE("bt_srch_dev_show_services()");
4331
4332 SEND_EVENT(bt_srch_data.win, BT_SHOW_DEV_SERVICES, 0, 0);
4333
4334 return MFW_EVENT_CONSUMED;
4335 }
4336
4337 /*
4338 ** CQ21843 : Menu Action function
4339 */
4340 static int bt_srch_dev_set_name (MfwMnu * mnu, MfwMnuItem * item)
4341 {
4342 T_MFW_BT_STATUS btRetVal;
4343 T_MMI_BtData *data = &bt_data;
4344 T_MFW_BT_REM_DEVICE_INFO *cur_device;
4345
4346 MfwHnd win = mfw_parent(mfw_header());
4347
4348 MFW_BT_TRACE("bt_srch_dev_set_name()");
4349
4350 cur_device = &bt_srch_data.srch_bt_dev_list[bt_srch_data.srch_bt_cur_dev_idx];
4351
4352 if (data->bt_dev_name_win == (void *)0)
4353 {
4354 data->bt_DevNameForStartup = FALSE;
4355
4356 data->bt_dev_name_win = mmi_bt_dev_name_create(win);
4357
4358 if (data->bt_dev_name_win != (void *)0)
4359 {
4360 SEND_EVENT(data->bt_dev_name_win, BT_SET_REM_DEV_NAME, 0, (void *)cur_device);
4361 }
4362 else
4363 {
4364 MFW_BT_TRACE("bt_srch_dev_set_name() : Unable to create Device Name Win!");
4365 }
4366 }
4367 else
4368 {
4369 MFW_BT_TRACE("bt_srch_dev_set_name() : Device Name Win already active");
4370 }
4371 return MFW_EVENT_CONSUMED;
4372 }
4373
4374 static int bt_srch_dev_add_known (MfwMnu * mnu, MfwMnuItem * item)
4375 {
4376 T_MFW_BT_STATUS btRetVal;
4377 T_MFW_BT_REM_DEVICE_INFO *cur_device;
4378
4379
4380 cur_device = &bt_srch_data.srch_bt_dev_list[bt_srch_data.srch_bt_cur_dev_idx];
4381 MFW_BT_TRACE_P7("bt_srch_dev_add_known(), Idx %d, BD_ADDR 0x%02x%02x%02x%02x%02x%02x",
4382 bt_srch_data.srch_bt_cur_dev_idx,
4383 cur_device->bd_addr[0],
4384 cur_device->bd_addr[1],
4385 cur_device->bd_addr[2],
4386 cur_device->bd_addr[3],
4387 cur_device->bd_addr[4],
4388 cur_device->bd_addr[5]);
4389
4390 /*
4391 ** CQ21834 : Ensure that the is_new value is set before writing the data to Flash, so that it will be
4392 ** set correctly when the handset is restarted.
4393 */
4394 cur_device->is_new = FALSE;
4395
4396 btRetVal = mfw_bt_dm_add_device(cur_device->bd_addr);
4397
4398 if (btRetVal != MFW_BT_SUCCESS)
4399 {
4400 /*
4401 ** CQ21834 : Failed to write the data to Flash, continue to treat the device as unknown.
4402 */
4403 cur_device->is_new = TRUE;
4404 MFW_BT_TRACE_P1("mfw_bt_dm_add_device returned error : %d", btRetVal);
4405 mmi_bluetooth_show_info(0, TxtFailed, TxtNull);
4406 }
4407 else
4408 {
4409 winShow(mfw_parent(mfw_header()));
4410 }
4411
4412 return MFW_EVENT_CONSUMED;
4413 }
4414
4415 static int bt_srch_dev_rem_known (MfwMnu * mnu, MfwMnuItem * item)
4416 {
4417 T_MFW_BT_STATUS btRetVal;
4418 T_MFW_BT_REM_DEVICE_INFO *cur_device;
4419
4420 MFW_BT_TRACE("bt_srch_dev_rem_known()");
4421
4422 cur_device = &bt_srch_data.srch_bt_dev_list[bt_srch_data.srch_bt_cur_dev_idx];
4423
4424 btRetVal = mfw_bt_dm_delete_device(cur_device->bd_addr);
4425
4426 if (btRetVal != MFW_BT_SUCCESS)
4427 {
4428 MFW_BT_TRACE_P1("mfw_bt_dm_delete_device returned error : %d", btRetVal);
4429 mmi_bluetooth_show_info(0, TxtFailed, TxtNull);
4430 }
4431 else
4432 {
4433 cur_device->is_new = TRUE;
4434 cur_device->link_key_present = FALSE;
4435
4436 winShow(mfw_parent(mfw_header()));
4437 }
4438
4439 return MFW_EVENT_CONSUMED;
4440 }
4441
4442 static void bt_srch_dev_list_searching_cb(T_MFW_HND Parent, ListMenuData * ListData)
4443 {
4444 T_MFW_WIN *win_data = ((T_MFW_HDR *)Parent)->data;
4445 T_MMI_BtSearchData *data = (T_MMI_BtSearchData *)win_data->user;
4446 MfwMnuItem *ptr_tempListItem;
4447 T_MFW_BT_REM_DEVICE_INFO *ptr_tempDevDb;
4448 int iLoop; /* CQ21841 : Loop identifier used while resetting the List labels */
4449
4450 MFW_BT_TRACE("bt_srch_dev_list_searching_cb()");
4451
4452 if ((ListData->Reason EQ LISTS_REASON_BACK) ||
4453 (ListData->Reason EQ LISTS_REASON_CLEAR) ||
4454 (ListData->Reason EQ LISTS_REASON_HANGUP))
4455 {
4456 /*
4457 ** Change the mode of the list
4458 */
4459 data->srch_bt_mode = BT_MODE_LIST_COMPLETE;
4460
4461 /*
4462 ** Stop the Search Now ... even if there are more entries waiting in the buffer, they will be ignored.
4463 */
4464 mfw_bt_dm_cancel_search();
4465
4466 /*
4467 ** Destroy the window and recreate it
4468 */
4469 listsDestroy(ListData->win);
4470
4471 /*
4472 ** Allocate memory to copy the devices already listed, copy the active data,
4473 ** and free the memory set aside for ALL the devices to be listed.
4474 */
4475
4476 ptr_tempListItem = (MfwMnuItem *)mfwAlloc(data->srch_bt_device_count * sizeof(MfwMnuItem));
4477 if (ptr_tempListItem != (MfwMnuItem *)0)
4478 {
4479 /*
4480 ** Copy the list of items
4481 */
4482 memcpy(ptr_tempListItem, data->srch_bt_list_devices_menu_data.List, (data->srch_bt_device_count * sizeof(MfwMnuItem)));
4483
4484 /*
4485 ** Free the first (and larger) list
4486 */
4487 mfwFree((U8 *)data->srch_bt_list_devices_menu_data.List, (U16)(data->srch_bt_num_devices * sizeof(MfwMnuItem)));
4488
4489 data->srch_bt_list_devices_menu_data.List = ptr_tempListItem;
4490 }
4491
4492 /*
4493 ** Repeat for the 'Device List'
4494 */
4495 ptr_tempDevDb = (T_MFW_BT_REM_DEVICE_INFO *)mfwAlloc(data->srch_bt_device_count * sizeof(T_MFW_BT_REM_DEVICE_INFO));
4496 if (ptr_tempDevDb!= (T_MFW_BT_REM_DEVICE_INFO *)0)
4497 {
4498 /*
4499 ** Copy the list of devices
4500 */
4501 memcpy(ptr_tempDevDb, data->srch_bt_dev_list, (data->srch_bt_device_count * sizeof(T_MFW_BT_REM_DEVICE_INFO)));
4502
4503 /*
4504 ** Free the first (and larger) list
4505 */
4506 mfwFree((U8 *)data->srch_bt_dev_list, (U16)(data->srch_bt_num_devices * sizeof(T_MFW_BT_REM_DEVICE_INFO)));
4507
4508 data->srch_bt_dev_list = ptr_tempDevDb;
4509 }
4510
4511 /*
4512 ** Configure some other List parameters
4513 */
4514 data->srch_bt_num_devices = data->srch_bt_device_count;
4515 data->srch_bt_list_devices_menu_data.ListLength = data->srch_bt_device_count;
4516 data->srch_bt_list_devices_menu_data.Attr->nItems = data->srch_bt_device_count;
4517
4518 data->srch_bt_list_devices_menu_data.Attr->hdrId = TxtBtDevices;
4519
4520 data->srch_bt_list_devices_menu_data.LeftSoftKey = TxtSoftOptions;
4521 data->srch_bt_list_devices_menu_data.RightSoftKey = TxtSoftBack;
4522
4523 /*
4524 ** CQ21842 : Modify the List Key Events so that it handles all teh keys it requires.
4525 */
4526 data->srch_bt_list_devices_menu_data.KeyEvents = KEY_CLEAR | KEY_RIGHT | KEY_LEFT | KEY_MNUUP | KEY_MNUDOWN |KEY_HUP;
4527
4528 data->srch_bt_list_devices_menu_data.autoDestroy = TRUE;
4529
4530 data->srch_bt_dev_list_cb = (ListCbFunc)bt_srch_dev_list_listmnu_cb;
4531
4532 /*
4533 ** CQ21841 : For each device in the list, reset the string pointer because it will be pointing to the old device
4534 ** list which has just been freed
4535 */
4536 for (iLoop = 0; iLoop < data->srch_bt_num_devices; iLoop++)
4537 data->srch_bt_list_devices_menu_data.List[iLoop].str = data->srch_bt_dev_list[iLoop].name;
4538
4539 /*
4540 ** Recreate the menu with the new details;
4541 */
4542 if (listDisplayListMenu(data->win, &data->srch_bt_list_devices_menu_data, data->srch_bt_dev_list_cb, FALSE) != LISTS_FAIL)
4543 data->srch_bt_dev_list_win = data->srch_bt_list_devices_menu_data.win;
4544
4545 }
4546
4547 return;
4548 }
4549
4550 static void bt_srch_dev_list_listmnu_cb(T_MFW_HND Parent, ListMenuData * ListData)
4551 {
4552 T_MFW_WIN *win_data = ((T_MFW_HDR *)Parent)->data;
4553 //T_MMI_BtSearchData *data = (T_MMI_BtSearchData *)win_data->user;
4554 T_MMI_BtSearchData *data = &bt_srch_data;
4555 MfwMnuItem *ptr_tempListItem;
4556 T_MFW_BT_REM_DEVICE_INFO *ptr_tempDevDb;
4557
4558 MFW_BT_TRACE_P1("bt_srch_dev_list_listmnu_cb(), with reason %d", ListData->Reason);
4559
4560 if ((ListData->Reason EQ LISTS_REASON_BACK) ||
4561 (ListData->Reason EQ LISTS_REASON_CLEAR) ||
4562 (ListData->Reason EQ LISTS_REASON_HANGUP))
4563 {
4564 /*
4565 ** Destroy the window --- Not sure if this is required! ... leave it out for now
4566 */
4567 listsDestroy(ListData->win);
4568
4569 /*
4570 ** Free the memory set aside for ALL the devices to be listed.
4571 ** CQ21834 : Use the "ListLength" value as this will also include the "No Devices" Entry for Known Devices.
4572 */
4573 mfwFree((U8 *)data->srch_bt_list_devices_menu_data.List, (U16)(data->srch_bt_list_devices_menu_data.ListLength * sizeof(MfwMnuItem)));
4574 data->srch_bt_list_devices_menu_data.List = (void *)0;
4575
4576 /*
4577 ** Repeat for the 'Device List'
4578 */
4579 mfwFree((U8 *)data->srch_bt_dev_list, (U16)(data->srch_bt_num_devices * sizeof(T_MFW_BT_REM_DEVICE_INFO)));
4580 data->srch_bt_dev_list = (void *)0;
4581
4582 /*
4583 ** Configure some other List parameters
4584 */
4585 data->srch_bt_num_devices = 0;
4586 data->srch_bt_device_count = 0;
4587 data->srch_bt_list_devices_menu_data.ListLength = 0;
4588 data->srch_bt_list_devices_menu_data.Attr->nItems = 0;
4589
4590 data->srch_bt_list_devices_menu_data.Attr->hdrId = 0;
4591
4592 data->srch_bt_list_devices_menu_data.LeftSoftKey = 0;
4593 data->srch_bt_list_devices_menu_data.RightSoftKey = 0;
4594 data->srch_bt_list_devices_menu_data.autoDestroy = TRUE;
4595
4596 data->srch_bt_dev_list_cb = (ListCbFunc)0;
4597
4598 data->srch_bt_dev_list_win = 0;
4599 data->srch_bt_mode = BT_MODE_NO_SEARCH;
4600
4601 /*
4602 ** Destroy the "Bt Search Window" and return to the underlying Menu
4603 */
4604 SEND_EVENT(data->win, BT_DISABLE_SEARCH, 0, 0);
4605
4606 }
4607
4608 return;
4609 }
4610
4611 static void bt_srch_service_list_listmnu_cb(T_MFW_HND Parent, ListMenuData * ListData)
4612 {
4613 T_MFW_WIN *win_data = ((T_MFW_HDR *)Parent)->data;
4614 T_MMI_BtSearchData *data = (T_MMI_BtSearchData *)win_data->user;
4615 MfwMnuItem *ptr_tempListItem;
4616 T_MFW_BT_REM_DEVICE_INFO *ptr_tempDevDb;
4617
4618 MFW_BT_TRACE("bt_srch_service_list_listmnu_cb()");
4619
4620 if ((ListData->Reason EQ LISTS_REASON_BACK) ||
4621 (ListData->Reason EQ LISTS_REASON_CLEAR) ||
4622 (ListData->Reason EQ LISTS_REASON_HANGUP))
4623 {
4624 /*
4625 ** Destroy the window --- Not sure if this is required! ... leave it out for now
4626 */
4627 listsDestroy(ListData->win);
4628
4629 /*
4630 ** Free the memory set aside for ALL the devices to be listed.
4631 */
4632 mfwFree((U8 *)data->srch_bt_show_services_menu_data.List, (U16)(data->srch_bt_show_services_menu_data.ListLength * sizeof(MfwMnuItem)));
4633 data->srch_bt_show_services_menu_data.List = (void *)0;
4634
4635 /*
4636 ** Configure some other List parameters
4637 */
4638 data->srch_bt_show_services_menu_data.ListLength = 0;
4639 data->srch_bt_show_services_menu_data.Attr->nItems = 0;
4640
4641 data->srch_bt_show_services_menu_data.Attr->hdrId = 0;
4642
4643 data->srch_bt_show_services_menu_data.LeftSoftKey = 0;
4644 data->srch_bt_show_services_menu_data.RightSoftKey = 0;
4645 data->srch_bt_show_services_menu_data.autoDestroy = TRUE;
4646
4647 data->srch_bt_show_services_win = 0;
4648 }
4649
4650 return;
4651 }
4652
4653 static int bt_count_dev_services(T_MFW_BT_SERVICE_MASK services, T_MFW_BT_SERVICE_MASK *srv_mask_arry)
4654 {
4655 ULONG chk_serv = 2;
4656 int iLoop;
4657 int iCount = 0;
4658
4659 MFW_BT_TRACE_P1("bt_count_dev_services() : services 0x%08lx", services);
4660
4661 for (iLoop = BTA_RES_SERVICE_ID + 1; iLoop < BTA_MAX_SERVICE_ID ; iLoop++)
4662 {
4663 MFW_BT_TRACE_P4("bt_count_dev_services > Idx %d, Count %d, Services 0x%08lx, chk_srv 0x%08lx",
4664 iLoop, iCount, services, chk_serv);
4665
4666 if ((services & chk_serv) != 0)
4667 {
4668 MFW_BT_TRACE_P2("bt_count_dev_services > Idx %d, Service 0x%08lx", iCount, chk_serv);
4669 srv_mask_arry[iCount] = chk_serv;
4670
4671 iCount++;
4672 }
4673
4674 chk_serv *= 2;
4675 }
4676
4677 MFW_BT_TRACE_P1("bt_count_dev_services > Number of Services Found : %d" , iCount);
4678
4679 return iCount;
4680 }
4681
4682 static int bt_get_TxtId_for_service(T_MFW_BT_SERVICE_MASK service)
4683 {
4684 int TxtId;
4685
4686 MFW_BT_TRACE("bt_get_TxtId_for_service()");
4687
4688 switch (service)
4689 {
4690 case BTA_SPP_SERVICE_MASK:
4691 TxtId = TxtBtSerialPort;
4692 break;
4693
4694 case BTA_DUN_SERVICE_MASK:
4695 TxtId = TxtBtDialUpNetworking;
4696 break;
4697
4698 case BTA_FAX_SERVICE_MASK:
4699 TxtId = TxtFax;
4700 break;
4701
4702 case BTA_LAP_SERVICE_MASK:
4703 TxtId = TxtBtLanAccess;
4704 break;
4705
4706 case BTA_HSP_SERVICE_MASK:
4707 TxtId = TxtBtHeadSet;
4708 break;
4709
4710 case BTA_HFP_SERVICE_MASK:
4711 TxtId = TxtBtHandsFree;
4712 break;
4713
4714 case BTA_OP_SERVICE_MASK:
4715 TxtId = TxtBtObjectPush;
4716 break;
4717
4718 case BTA_FT_SERVICE_MASK:
4719 TxtId = TxtBtFileTransfer;
4720 break;
4721
4722 case BTA_CT_SERVICE_MASK:
4723 TxtId = TxtBtCordlessTelephony;
4724 break;
4725
4726 case BTA_IC_SERVICE_MASK:
4727 TxtId = TxtBtIntercom;
4728 break;
4729
4730 default:
4731 TxtId = TxtBtUnknownService;
4732 }
4733
4734 return TxtId;
4735 }
4736