comparison g23m/condat/ms/src/mfw/mfw_bte.c @ 0:509db1a7b7b8

initial import: leo2moko-r1
author Space Falcon <falcon@ivan.Harhan.ORG>
date Mon, 01 Jun 2015 03:24:05 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:509db1a7b7b8
1 /*
2 +-------------------------------------------------------------------+
3 | PROJECT: MMI-Framework (8445) $Workfile:: mfw_bt.c $|
4 | $Author:: NDH $Revision:: 1 $|
5 | CREATED: 17.04.04 $Modtime:: 17.04.04 17: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 "bta_riviera.h"
40
41 #include "bta_api.h"
42 #include "mfw_bt_geh.h"
43 #include "mfw_bte.h"
44 #include "mfw_bt_dm.h"
45 #include "mfw_bt_dg.h"
46 #include "mfw_bt_ag.h"
47 #include "mfw_bt_op.h"
48 #include "mfw_bt_ft.h"
49 #include "mfw_bt_flash.h"
50
51 #include "mfw_utils.h"
52
53 /*
54 ** Define Module wide variables
55 */
56 static SHORT Mfw_Bt_Ge_Sigbuf_Id = -1;
57 static BOOLEAN Mfw_Bt_Ge_InProgress;
58
59 static T_MFW_STARTUP_VISIBILITY startup_visibility;
60
61 /*
62 ** Local Function Prototypes
63 */
64 static void mfw_bt_send_cb_notify_ind (void);
65
66 /*
67 ** Define External variables and references
68 */
69 EXTERN MfwHdr * current_mfw_elem;
70 /*
71 ** Module Function Definitoins
72 */
73
74
75
76 /*******************************************************************************
77
78 $Function: mfw_bt_enable
79
80 $Description: This function will start the whole process of enabling Bluetooth.
81
82 $Returns: MFW_BT_FAIL if the chip is not stopped or if the generic event handler
83 doesn't start correctly.
84
85 $Arguments: startup_visibility. Visibility set by the BMI. MFW_BT_DEFAULT_VIS if
86 using the settings stored in flash.
87
88 *******************************************************************************/
89 T_MFW_BT_STATUS mfw_bt_enable(T_MFW_STARTUP_VISIBILITY startup_visibility )
90 {
91 UINT8 delay_counter = 0;
92 T_RV_RET bt_start_status = 0;
93 T_MFW_BT_STATUS status;
94 // static tBTA_SYS_START_CBACK *fp;
95 // fp= (tBTA_SYS_START_CBACK *)&mfw_bt_dm_security_cb;
96
97 /* first, enable the event handler */
98 status = mfw_bt_ge_enable();
99 if( status != MFW_BT_SUCCESS )
100 return status;
101
102 /* start the system */
103 if( BTA_SysStart((tBTA_SYS_START_CBACK *)(&mfw_bt_dm_security_cb) ) != RV_OK )
104 // if( BTA_SysStart(fp) != RV_OK )
105 {
106 MFW_BT_TRACE( "[mfw_bt]: failed to start BT chipset" );
107 return MFW_BT_FAIL;
108 }
109 /* the start-up procedure has been started. We will receive an
110 event when it is done */
111 MFW_BT_TRACE( "[mfw_bt]: BT is starting" );
112 return MFW_BT_SUCCESS;
113
114 }
115
116
117
118
119 /* */
120 /*******************************************************************************
121
122 $Function: mfw_bt_enable_cb
123
124 $Description: mfw_bt_enable will cause a BTA_DM_SYS_START_EVT to be sent. At this
125 moment we call BTA_EnableBluetooth. When we receive
126 BTA_DM_ENABLE_EVT, we call this function.
127
128 $Returns: Will send a BMI signal if there is no default name. If the user cancels the
129 input, BT will then be stopped.
130 Will send a E_BT_ENABLE_CMPL event when the initialization is done.
131
132 $Arguments: none
133
134 *******************************************************************************/
135 void mfw_bt_enable_cb(void)
136 {
137 UINT8* device_name;
138 T_MFW_BT_REM_DEVICE *ptr_device_array[MFW_BT_NUM_REM_DEVICE];
139 UINT8 number_of_devices;
140 T_MFW_BT_ENABLE_CMPL enable_evt_data;
141
142
143 mfw_bt_cb.is_started = TRUE;
144
145 /* set device name */
146 device_name = mfw_bt_read_local_name( );
147 if( *device_name == NULL )
148 {
149 /* no name yet. Use default one, and ask the user to specify a new one */
150 BTA_DmSetDeviceName((char*)MFW_BT_DEVICE_NAME);
151 mfw_bt_cb.is_name_requested = TRUE;
152 mfw_bt_signal(E_BT_DM_DEV_NAME_REQ, NULL);
153 }
154 else
155 BTA_DmSetDeviceName( (char*)device_name );
156
157 /* set visibility and connectability */
158 if( startup_visibility == MFW_BT_DEFAULT_VIS )
159 {
160 if( mfw_bt_read_visibility( ) == TRUE )
161 {
162 BTA_DmSetVisibility( BTA_DM_GENERAL_DISC, BTA_DM_CONN);
163 }
164 else
165 {
166 BTA_DmSetVisibility( BTA_DM_NON_DISC, BTA_DM_NON_CONN);
167 }
168 }
169 else
170 {
171 BTA_DmSetVisibility( startup_visibility, BTA_DM_NON_CONN);
172 }
173
174
175 /* Update BTA with peer device information stored in NVRAM */
176 /* first, get all the devices */
177 mfw_bt_get_device_by_service(0,
178 &ptr_device_array[0],
179 &number_of_devices);
180
181 /* then add these devices to BTA database. */
182 for ( ; number_of_devices>0 ; number_of_devices-- )
183 {
184 if(ptr_device_array[number_of_devices]->link_key_present)
185 {
186 BTA_DmAddDevice(ptr_device_array[number_of_devices]->bd_addr,
187 ptr_device_array[number_of_devices]->link_key,
188 ptr_device_array[number_of_devices]->trusted_services,
189 ptr_device_array[number_of_devices]->is_trusted);
190 }
191 else if (ptr_device_array[number_of_devices]->is_trusted)
192 {
193 BTA_DmAddDevice(ptr_device_array[number_of_devices]->bd_addr,
194 NULL,
195 ptr_device_array[number_of_devices]->trusted_services,
196 ptr_device_array[number_of_devices]->is_trusted);
197 }
198 }
199
200 /* initialize all the sub-parts => BT profiles. THIS CODE IS ABSOLUTELY NOT DYNAMIC... Does it
201 need to be??? */
202 mfw_bt_ag_init();
203 mfw_bt_dg_init();
204 mfw_bt_op_init();
205 mfw_bt_ft_init();
206
207 /* finally platform-specific initialization */
208 //nothing to do for the time being.
209
210 /* store the new settings. this stores base conf file */
211 mfw_bt_store_status(TRUE);
212
213 enable_evt_data.Success = TRUE;
214 mfw_bt_signal(E_BT_ENABLE_CMPL, (void*)&enable_evt_data );
215
216 return;
217
218 }
219
220 /*******************************************************************************
221
222 $Function: mfw_bt_disable
223
224 $Description: This function stops the BT system.
225
226 $Returns: None
227
228 $Arguments: None
229
230 *******************************************************************************/
231 void mfw_bt_disable(void)
232 {
233 /* disable BT. DM handler will then receive an DISABLE event => will stop the chipset
234 and kill the generic event handler. */
235 BTA_DisableBluetooth( );
236
237 return;
238 }
239
240
241
242 /*******************************************************************************
243
244 $Function: mfw_bt_init
245
246 $Description: This function initialises the Mfw Bluetooth Persistent Data on Power Up.
247
248 $Returns: None
249
250 $Arguments: None
251
252 *******************************************************************************/
253 void mfw_bt_init(void)
254 {
255
256 /*
257 ** Read the Known Devices from FFS
258 */
259 mfw_bt_flash_init( );
260
261 /*
262 ** The rest is down to you Thomas
263 */
264
265 return;
266 }
267
268 /*******************************************************************************
269
270 $Function: mfw_bt_exit
271
272 $Description: This function will tidy up any resources used by the Mfw Bluetooth Module
273 on Power Down
274
275 $Returns: None
276
277 $Arguments: None
278
279 *******************************************************************************/
280 void mfw_bt_exit(void)
281 {
282 /* nothing to do here... RAM will be automatically cleaned, and the flash wasn't modified */
283
284 return;
285 }
286
287 /*******************************************************************************
288
289 $Function: mfw_bt_create
290
291 $Description: This function initialises an Mfw Bluetooth entity and adds it to the Window Stack
292
293 $Returns: T_MFW_HND : A handle for the entity
294
295 $Arguments: T_MFW_HND : Parent Window Handle
296 T_MFW_EVENT : Event Mask of the events to be handled
297 T_MFW_CB : Callback function to handle the events
298
299 *******************************************************************************/
300 T_MFW_HND mfw_bt_create(T_MFW_HND hWin, T_MFW_EVENT event, T_MFW_CB cbfunc)
301 {
302 T_MFW_HDR *hdr;
303 T_MFW_BT *bt_para;
304
305 MFW_BT_TRACE("mfw_bt_create");
306
307 hdr = (T_MFW_HDR *) mfwAlloc(sizeof (T_MFW_HDR));
308 bt_para = (T_MFW_BT *) mfwAlloc(sizeof (T_MFW_BT));
309
310 if (!hdr OR !bt_para)
311 return FALSE;
312
313 /*
314 * initialisation of the handler
315 */
316 bt_para->emask = event;
317 bt_para->handler = cbfunc;
318
319 hdr->data = bt_para; /* store parameter in node */
320 hdr->type = MfwTypBt; /* store type of event handler */
321
322 /*
323 * installation of the handler
324 */
325 return mfwInsert((T_MFW_HDR *)hWin, hdr);
326 }
327
328 /*******************************************************************************
329
330 $Function: mfw_bt_delete
331
332 $Description: This function clears down an Mfw Bluetooth entity and removes it from the
333 Window Stack
334
335 $Returns: T_MFW_RES : The result of the function
336
337 $Arguments: T_MFW_HND : The Handle of the entity to be removed
338
339 *******************************************************************************/
340 T_MFW_RES mfw_bt_delete(T_MFW_HND hnd)
341 {
342 MFW_BT_TRACE("mfw_bt_delete");
343
344 if (!hnd OR !((T_MFW_HDR *)hnd)->data)
345 return MFW_RES_ILL_HND;
346
347 if (!mfwRemove((T_MFW_HDR *)hnd))
348 return MFW_RES_ILL_HND;
349
350 mfwFree((U8 *)(((T_MFW_HDR *) hnd)->data),sizeof(T_MFW_BT));
351 mfwFree((U8 *)hnd,sizeof(T_MFW_HDR));
352
353 return MFW_RES_OK;
354 }
355
356 /*******************************************************************************
357
358 $Function: mfw_bt_signal
359
360 $Description: This function sends the Mfw Bluetooth events from the Mfw to the BMI.
361
362 $Returns: None
363
364 $Arguments: T_MFW_EVENT : The event to be sent to the BMI
365 void * : Pointer to the Event data
366
367 *******************************************************************************/
368 void mfw_bt_signal(T_MFW_EVENT event, void *para)
369 {
370 UBYTE temp;
371
372 temp = dspl_Enable(0);
373
374
375 if (mfwSignallingMethod EQ 0)
376 {
377 /*
378 * focus is on a window
379 */
380 if (mfwFocus)
381 {
382 /*
383 * send event to sim management
384 * handler if available
385 */
386 if (mfw_bt_sign_exec (mfwFocus, event, para))
387 {
388 dspl_Enable(temp);
389 return;
390 }
391 }
392
393 /*
394 * actual focussed window is not available
395 * or has no network management registration
396 * handler, then search all nodes from the root.
397 */
398 if (mfwRoot)
399 mfw_bt_sign_exec (mfwRoot, event, para);
400 }
401 else
402 {
403 MfwHdr * h = 0;
404
405 /*
406 * Focus set, then start here
407 */
408 if (mfwFocus)
409 h = mfwFocus;
410
411 /*
412 * Focus not set, then start root
413 */
414 if (!h)
415 h = mfwRoot;
416
417 /*
418 * No elements available, return
419 */
420 while (h)
421 {
422 /*
423 * Signal consumed, then return
424 */
425 if (mfw_bt_sign_exec (h, event, para))
426 {
427 dspl_Enable(temp);
428 return;
429 }
430
431 /*
432 * All windows tried inclusive root
433 */
434 if (h == mfwRoot)
435 {
436 dspl_Enable(temp);
437 return;
438 }
439
440 /*
441 * get parent window
442 */
443 h = mfwParent(mfwParent(h));
444
445 if (h)
446 h = ((MfwWin * )(h->data))->elems;
447 }
448
449 mfw_bt_sign_exec (mfwRoot, event, para);
450
451 }
452
453 dspl_Enable(temp);
454
455 return;
456 }
457
458 /*******************************************************************************
459
460 $Function: mfw_bt_sign_exec
461
462 $Description: This function sends the Mfw Bluetooth events from the Mfw to the BMI.
463
464 $Returns: None
465
466 $Arguments: None
467
468 *******************************************************************************/
469
470 BOOL mfw_bt_sign_exec (T_MFW_HDR * cur_elem, T_MFW_EVENT event, T_MFW_BT_PARA * para)
471 {
472 MFW_BT_TRACE("mfw_bt_sign_exec");
473
474 while (cur_elem)
475 {
476 /*
477 * event handler is available
478 */
479 if (cur_elem->type EQ MfwTypBt)
480 {
481 T_MFW_BT * bt_data;
482 /*
483 * handler is CM management handler
484 */
485 bt_data = (T_MFW_BT *)cur_elem->data;
486 if (bt_data->emask & event)
487 {
488 /*
489 * event is expected by the call back function
490 */
491 bt_data->event = event;
492 switch (event)
493 {
494 /*
495 ** Generic Events
496 */
497 case E_BT_ENABLE_CMPL:
498 memcpy (&bt_data->para, para, sizeof (T_MFW_BT_ENABLE_CMPL));
499 break;
500
501 case E_BT_DISABLE_CMPL:
502 memset(&bt_data->para, 0x00, sizeof(T_MFW_BT_PARA));
503 break;
504
505 /*
506 ** Device Manager Events
507 */
508 case E_BT_DM_LINK_UP:
509 memcpy (&bt_data->para, para, sizeof (T_MFW_BT_DM_LINK_UP));
510 break;
511
512 case E_BT_DM_LINK_DOWN:
513 memcpy (&bt_data->para, para, sizeof (T_MFW_BT_DM_LINK_DOWN));
514 break;
515
516 case E_BT_DM_INQ_RES:
517 memcpy (&bt_data->para, para, sizeof (T_MFW_BT_DM_INQ_RES));
518 break;
519
520 case E_BT_DM_INQ_CMPL:
521 memcpy (&bt_data->para, para, sizeof (T_MFW_BT_DM_INQ_CMPL));
522 break;
523
524 case E_BT_DM_DISC_RES:
525 memcpy (&bt_data->para, para, sizeof (T_MFW_BT_DM_DISC_RES));
526 break;
527
528 case E_BT_DM_DISC_CMPL:
529 memset(&bt_data->para, 0x00, sizeof(T_MFW_BT_PARA));
530 break;
531
532 case E_BT_DM_PIN_REQ:
533 memcpy (&bt_data->para, para, sizeof (T_MFW_BT_DM_PIN_REQ));
534 break;
535
536 case E_BT_DM_AUTH_CMPL:
537 memcpy (&bt_data->para, para, sizeof (T_MFW_BT_DM_AUTH_CMPL));
538 break;
539
540 case E_BT_DM_AUTHORIZE_REQ:
541 memcpy (&bt_data->para, para, sizeof (T_MFW_BT_DM_AUTHORIZE_REQ));
542 break;
543
544 case E_BT_DM_DEV_NAME_REQ:
545 memset(&bt_data->para, 0x00, sizeof(T_MFW_BT_PARA));
546 break;
547
548 case E_BT_DM_SIG_STRENGTH_IND:
549 memcpy (&bt_data->para, para, sizeof (T_MFW_BT_DM_SIG_STRENGTH_IND));
550 break;
551
552 }
553
554 /*
555 * if call back defined, call it
556 */
557 if (bt_data->handler)
558 {
559 // store current mfw elem
560 current_mfw_elem = cur_elem;
561
562 if ((*(bt_data->handler)) (bt_data->event, (void *)&bt_data->para))
563 return TRUE;
564 }
565 }
566 }
567 cur_elem = cur_elem->next;
568 }
569 return FALSE;
570 }
571
572
573 /*******************************************************************************
574
575 $Function: mfw_bt_ge_enable
576
577 $Description: This function initialises the Generic Event Handler, it should be active only
578 when bluetooth is enabled.
579
580 $Returns: MFW_BT_UNABLE_TO_CREATE_EVT_BUF : Failed to start - memory problems
581 MFW_BT_SUCCESS : Started OK, and Ready
582
583 $Arguments: None
584
585 *******************************************************************************/
586
587 T_MFW_BT_STATUS mfw_bt_ge_enable (void)
588 {
589 SHORT cbufRetVal;
590
591 MFW_BT_TRACE("mfw_bt_ge_enable");
592
593 /*
594 ** Try to create the Circular Event Buffer
595 */
596 cbufRetVal = mfw_cbuf_create(MFW_BT_MAX_SIG_Q_ENTRIES, /* Max Entires */
597 sizeof(T_MFW_BT_SIGNALS), /* Item Size */
598 FALSE, /* Don't Overwrite */
599 0xFF, /* Null Character */
600 FALSE, /* Dynamic Buffer */
601 (void *)0); /* Buffer pointer not required */
602
603 if (cbufRetVal == MFW_CBUF_MEM_ALLOC_FAILURE)
604 {
605
606 MFW_BT_TRACE("mfw_bt_ge_enable > Buffer Creation Failed with Mem Constraints");
607
608 /*
609 ** Failed due to memory constraints, try again with half the number of entries
610 */
611 cbufRetVal = mfw_cbuf_create(MFW_BT_MAX_SIG_Q_ENTRIES/2, /* Max Entires */
612 sizeof(T_MFW_BT_SIGNALS), /* Item Size */
613 FALSE, /* Don't Overwrite */
614 0xFF, /* Null Character */
615 FALSE, /* Dynamic Buffer */
616 (void *)0); /* Buffer pointer not required */
617 /*
618 ** All MFW_CBUF error codes are negative, 0 or a positive value from mfw_cbuf_create is a valid buffer Id
619 */
620 if (cbufRetVal < 0)
621 {
622
623 MFW_BT_TRACE_P1("mfw_bt_ge_enable > Unable to Create Buffer : Error %d", cbufRetVal);
624
625 /*
626 ** Failed to allocate buffer, return an error
627 */
628 return MFW_BT_UNABLE_TO_CREATE_EVT_BUF;
629 }
630
631 }
632 else if (cbufRetVal < 0)
633 {
634
635 MFW_BT_TRACE_P1("mfw_bt_ge_enable > Unable to Create Buffer : Error %d", cbufRetVal);
636
637 /*
638 ** Failed to allocate buffer, return an error
639 */
640 return MFW_BT_UNABLE_TO_CREATE_EVT_BUF;
641 }
642
643
644 MFW_BT_TRACE_P1("mfw_bt_ge_enable > Buffer created successfully with Id %d", cbufRetVal);
645
646 /*
647 ** A buffer has been created, store the Id for future use.
648 */
649 Mfw_Bt_Ge_Sigbuf_Id = cbufRetVal;
650
651 return MFW_BT_SUCCESS;
652
653 }
654
655
656 /*******************************************************************************
657
658 $Function: mfw_bt_ge_disable
659
660 $Description: Disbales the Generic Event Handler, and releases the Dynamic Event Buffer
661
662 $Returns: None
663
664 $Arguments: None
665
666 *******************************************************************************/
667 void mfw_bt_ge_disable (void)
668 {
669
670 MFW_BT_TRACE("mfw_bt_ge_disable");
671
672
673 /*
674 ** Ensure the MFW Bluetooth Event handler is initialised
675 */
676 if (Mfw_Bt_Ge_Sigbuf_Id < 0)
677 {
678 MFW_BT_TRACE("mfw_bt_ge_disable > Bluetooth Module Not Initialised");
679 }
680 else
681 {
682 mfw_cbuf_delete(Mfw_Bt_Ge_Sigbuf_Id);
683
684 Mfw_Bt_Ge_Sigbuf_Id = -1;
685 }
686 }
687
688
689 /*******************************************************************************
690
691 $Function: mfw_bt_ge_post_event
692
693 $Description: This function stores the incoming event in the event buffer, and if required,
694 notifies the MMI Task
695
696 $Returns: MFW_BT_NOT_INITIALISED : Fn mfw_bt_ge_enable not called or failed
697 MFW_BT_INVALID_ORIG : Invalid Originator Id received
698 MFW_BT_INVALID_EVENT : Invalid Event Id received
699 MFW_BT_INVALID_DATA : Mismatch between the data pointer and datalen values
700 MFW_BT_FAILED_TO_STORE_EVENT : Event Buffer Full (check trace)
701 MFW_BT_SUCCESS : Event Stored successfuly
702
703 $Arguments: originator : Identifier for the originating profile that caused the event
704 eventId : Event Identifier (See BTA Specification)
705 data : pointer to the event data
706 dataLen : length of the event data in bytes (must be 0 if data is (void *)0)
707
708 *******************************************************************************/
709 T_MFW_BT_STATUS mfw_bt_ge_post_event (T_MFW_BT_ORIGINATORS originator,
710 ULONG eventId,
711 void * data,
712 int dataLen)
713 {
714 T_MFW_BT_SIGNALS sigBuffer;
715 USHORT numElements;
716 SHORT cbufRetVal;
717
718 MFW_BT_TRACE("mfw_bt_ge_post_event");
719
720 /*
721 ** Ensure the MFW Bluetooth Event handler is initialised
722 */
723 if (Mfw_Bt_Ge_Sigbuf_Id < 0)
724 {
725 MFW_BT_TRACE("mfw_bt_ge_post_event > Bluetooth Module Not Initialised");
726 return MFW_BT_NOT_INITIALISED;
727 }
728
729 /*
730 ** Validate the incoming Parameters
731 */
732
733 if ((originator >= MFW_BT_MAX_ORIGINATOR) ||
734 ((originator & (ULONG)0xFFFF) != 0))
735 {
736 MFW_BT_TRACE_P1("mfw_bt_ge_post_event > Originator Invalid : 0x%lx", originator);
737 return MFW_BT_INVALID_ORIG;
738 }
739
740 if (eventId > (ULONG)0xFFFF)
741 {
742 MFW_BT_TRACE_P1("mfw_bt_ge_post_event > Event Id Invalid : 0x%lx", eventId);
743 return MFW_BT_INVALID_EVENT;
744 }
745
746 if ((dataLen < 0) ||
747 ((data == (void *)0) && (dataLen != 0)) ||
748 ((data != (void *)0) && (dataLen == 0)))
749 {
750 MFW_BT_TRACE_P2("mfw_bt_ge_post_event > Data, DataLen combination Invalid : data 0x%lx, dataLen %d", data, dataLen);
751 return MFW_BT_INVALID_DATA;
752 }
753
754 /*
755 ** Create the Event for storage, which is combined from the OriginatorId and the EventId
756 */
757 sigBuffer.event = originator | eventId;
758
759 /*
760 ** Copy the Signal Data for storage
761 */
762 memcpy((void *)&sigBuffer.data, data, dataLen);
763
764 /*
765 ** Get the existing number of elements in the Event Buffer
766 */
767 numElements = mfw_cbuf_num_elements (Mfw_Bt_Ge_Sigbuf_Id);
768
769 /*
770 ** Post the event to the buffer
771 */
772 cbufRetVal = mfw_cbuf_put(Mfw_Bt_Ge_Sigbuf_Id, (void *)&sigBuffer);
773
774 if (cbufRetVal != MFW_CBUF_OK)
775 {
776 /*
777 ** Unable to store the data
778 */
779 MFW_BT_TRACE_P1("mfw_bt_ge_post_event > Unable to store the event : Error %d", cbufRetVal);
780
781 return MFW_BT_FAILED_TO_STORE_EVENT;
782 }
783
784 MFW_BT_TRACE("mfw_bt_ge_post_event > Event Successfully Stored");
785
786 /*
787 ** If required, Post the MMI_BT_CB_NOTIFY_RXD_IND Primitive
788 */
789 if ((numElements == 0) &&
790 (Mfw_Bt_Ge_InProgress == FALSE))
791 {
792 /*
793 ** Sending Primitive to MMI TASK
794 */
795 MFW_BT_TRACE("mfw_bt_ge_post_event > Sending Primitive to MMI TASK");
796 mfw_bt_send_cb_notify_ind();
797 }
798 #ifdef MFW_BT_DEBUG
799 else
800 {
801 /*
802 ** Sending Primitive to MMI TASK
803 */
804 MFW_BT_TRACE("mfw_bt_ge_post_event > No need to send Primitive to MMI TASK");
805 }
806 #endif
807
808 return MFW_BT_SUCCESS;
809 }
810
811
812 /*******************************************************************************
813
814 $Function: mfw_bt_cb_notify_rxd
815
816 $Description: This function is called on receipt of the MMI_BT_CB_NOTIFY_IND primitive, it reads
817 the events from the event buffer and passes the details to the appropriate Profile
818 Handler. It will process a Maximum of MFW_BT_MAX_CONSEC_SIG_PROC events
819 before reposting the primitive to the MMI Queue and relinquishing control.
820
821 $Returns: None
822
823 $Arguments: None
824
825 *******************************************************************************/
826 void mfw_bt_cb_notify_rxd(void)
827 {
828 T_MFW_BT_SIGNALS sigBuffer;
829 T_MFW_BT_ORIGINATORS originatorId;
830 T_MFW_BT_STATUS hndlrRetVal;
831 ULONG eventId;
832 UBYTE numSigsProcessed;
833 SHORT cbufRetVal;
834
835 MFW_BT_TRACE("mfw_bt_cb_notify_rxd");
836
837 if (Mfw_Bt_Ge_Sigbuf_Id < 0)
838 {
839 MFW_BT_TRACE("Mfw_Bt_cb_notify_rxd > Bluetooth Module Not Initialised");
840 return;
841 }
842
843 /*
844 ** Initialise Local and Module variables as required.
845 */
846 Mfw_Bt_Ge_InProgress = TRUE;
847 numSigsProcessed = 0;
848
849 /*
850 ** While there are events in the Buffer, and the maximum number of signals have not
851 ** been processed ...
852 */
853 while ((numSigsProcessed < MFW_BT_MAX_CONSEC_SIG_PROC) && (mfw_cbuf_num_elements(Mfw_Bt_Ge_Sigbuf_Id) > 0))
854 {
855 numSigsProcessed++;
856
857 /*
858 ** Read the event details from the buffer
859 */
860 cbufRetVal = mfw_cbuf_get(Mfw_Bt_Ge_Sigbuf_Id, (void *)&sigBuffer);
861
862 if (cbufRetVal != MFW_CBUF_OK)
863 {
864 Mfw_Bt_Ge_InProgress = FALSE;
865 (void)mfw_cbuf_reset(Mfw_Bt_Ge_Sigbuf_Id);
866 MFW_BT_TRACE_P1("Mfw_Bt_cb_notify_rxd > Unable to read events from Buffer : Error %d", cbufRetVal);
867 return;
868 }
869
870 /*
871 ** Seperate the Originator and Event Id values
872 */
873 originatorId = sigBuffer.event & (ULONG)0xFFFF0000;
874 eventId = sigBuffer.event & (ULONG)0x0000FFFF;
875
876 /*
877 ** switch on the originator Id
878 */
879 switch (originatorId)
880 {
881 case MFW_BT_DM_SECURITY:
882 hndlrRetVal = mfw_bt_dm_security_hndlr((T_MFW_BT_DM_SEC_EVT)eventId,
883 (T_MFW_BT_DM_SEC_SIG_DATA *)&sigBuffer.data.dmSecSignals);
884 break;
885
886 case MFW_BT_DM_SEARCH:
887 hndlrRetVal = mfw_bt_dm_search_hndlr((T_MFW_BT_DM_SRCH_EVT)eventId,
888 (T_MFW_BT_DM_SRCH_SIG_DATA *)&sigBuffer.data.dmSrchSignals);
889 break;
890
891 case MFW_BT_DG:
892 hndlrRetVal = mfw_bt_dg_hndlr((T_MFW_BT_DG_EVT)eventId,
893 (T_MFW_BT_DG_SIG_DATA *)&sigBuffer.data.dgSignals);
894 break;
895
896 case MFW_BT_AG:
897 hndlrRetVal = mfw_bt_ag_hndlr((T_MFW_BT_AG_EVT)eventId,
898 (T_MFW_BT_AG_SIG_DATA *)&sigBuffer.data.agSignals);
899 break;
900
901 case MFW_BT_OPC:
902 hndlrRetVal = mfw_bt_opc_hndlr((T_MFW_BT_OPC_EVT)eventId,
903 (T_MFW_BT_OPC_SIG_DATA *)&sigBuffer.data.opcSignals);
904 break;
905
906 case MFW_BT_OPS:
907 hndlrRetVal = mfw_bt_ops_hndlr((T_MFW_BT_OPS_EVT)eventId,
908 (T_MFW_BT_OPS_SIG_DATA *)&sigBuffer.data.opsSignals);
909 break;
910
911 case MFW_BT_FTC:
912 hndlrRetVal = mfw_bt_ftc_hndlr((T_MFW_BT_FTC_EVT)eventId,
913 (T_MFW_BT_FTC_SIG_DATA *)&sigBuffer.data.ftcSignals);
914 break;
915
916 case MFW_BT_FTS:
917 hndlrRetVal = mfw_bt_fts_hndlr((T_MFW_BT_FTS_EVT)eventId,
918 (T_MFW_BT_FTS_SIG_DATA *)&sigBuffer.data.ftsSignals);
919 break;
920
921 default:
922 MFW_BT_TRACE_P1("mfw_bt_cb_notify_rxd > Invalid Originator 0x%lx", originatorId);
923 hndlrRetVal = MFW_BT_SUCCESS; /* Set the return value to success because an error has already been reported */
924
925 }
926
927 if (hndlrRetVal <= 0)
928 {
929 /* Error reported by the handler, not a lot can be done, expect report it */
930 MFW_BT_TRACE_P2("mfw_bt_cb_notify_rxd > Error %d returned from Event handler for Originator 0x%lx", hndlrRetVal, originatorId);
931 }
932 }
933
934 Mfw_Bt_Ge_InProgress = FALSE;
935
936 /*
937 ** If there are still signals in the buffer, send another MMI_BT_CB_NOTIFY_RXD_IND primitive
938 */
939 if (mfw_cbuf_num_elements(Mfw_Bt_Ge_Sigbuf_Id) > 0)
940 {
941 MFW_BT_TRACE("Mfw_Bt_cb_notify_rxd > Send the MMI_BT_CB_NOTIFY_IND signal");
942 mfw_bt_send_cb_notify_ind();
943 }
944
945 return;
946 }
947
948
949 /**************************************************************************************************
950 **
951 ** Local Function Definitions
952 **
953 **************************************************************************************************/
954
955 #define hCommACI _ENTITY_PREFIXED(hCommACI)
956
957
958 /*******************************************************************************
959
960 $Function: mfw_bt_send_cb_notify_ind
961
962 $Description: This function posts the MMI_BT_CB_NOTIFY_IND primitive to the MMI Queue
963
964 $Returns: None
965
966 $Arguments: None
967
968 *******************************************************************************/
969 static void mfw_bt_send_cb_notify_ind (void)
970 {
971 #if defined (NEW_FRAME)
972 EXTERN T_HANDLE hCommACI;
973
974
975 ULONG signal_raw;
976 #else
977 EXTERN T_VSI_CHANDLE hCommACI;
978 #endif
979
980 PALLOC(bt_cb_notify_ind,MMI_BT_CB_NOTIFY_IND);
981
982 MFW_BT_TRACE("mfw_bt_send_cb_notify_ind");
983
984 #if defined (NEW_FRAME)
985 PSENDX(ACI,bt_cb_notify_ind);
986 #else
987 #if defined (_TMS470)
988 vsi_c_send("",hCommACI,D2P(bt_cb_notify_ind),
989 sizeof(T_PRIM_HEADER)+sizeof(T_MMI_BT_CB_NOTIFY_IND));
990 #else
991 PSEND(ACI,bt_cb_notify_ind);
992 #endif
993 #endif
994
995 return;
996
997 }