comparison src/ui3/mfw/mfw_BtipsOppc.c @ 420:e8ddbb0837ed

src/ui3: initial import of TCS3/LoCosto BMI & MFW code
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 21 Jan 2018 03:09:00 +0000
parents
children
comparison
equal deleted inserted replaced
419:59143cd42ec7 420:e8ddbb0837ed
1 /* =========================================================
2 * Texas Instruments OMAP(TM) Platform Software
3 * (c) Copyright Texas Instruments, Incorporated. All Rights Reserved.
4 *
5 * Use of this software is controlled by the terms and conditions found
6 * in the license agreement under which this software has been supplied.
7 * ========================================================== */
8 /*
9 $Project name: Basic Bluetooth MMI
10 $Project code:
11 $Module: Bluetooth BMG MFW
12 $File: Mfw_BtipsOppc.c
13 $Revision: 1.0
14 $Author: Texas Instruments
15 $Date: 26/06/07
16
17 ********************************************************************************
18
19 Description:
20
21 This module provides the OPP Client APPlication functionality.
22
23 ********************************************************************************
24 $History: Mfw_BtipsOppc.c
25
26 26/06/07 Sasken original version
27
28 $End
29
30 *******************************************************************************/
31
32
33
34
35 /*******************************************************************************
36
37 Include files
38
39 *******************************************************************************/
40
41 #define ENTITY_MFW
42 /* includes */
43
44 #include <string.h>
45
46 #if defined (NEW_FRAME)
47
48 #include "typedefs.h"
49 #include "vsi.h"
50 #include "pei.h"
51 #include "custom.h"
52 #include "gsm.h"
53 #include "prim.h"
54
55 #else
56
57 #include "STDDEFS.H"
58 #include "custom.h"
59 #include "gsm.h"
60 #include "vsi.h"
61
62 #endif
63
64 #ifdef FF_MMI_BTIPS_APP
65 #include "osapi.h"
66 #include "btl_common.h"
67 #include "debug.h"
68
69 //#include "../app_main.h"
70 #include "btl_oppc.h"
71 #include "btl_config.h"
72 #include "bthal_fs.h"
73 //#include "../../btl/inc/int/obstore.h"
74 #include "obstore.h"
75
76 #include "mfw_BtipsOppc.h"
77 #include "Mfw_mfw.h"
78 #include "mfw_Btips.h"
79 #include "mfw_ffs.h"
80
81 extern int oppc_files_count;
82 //Array to load fileNames in content directory
83 extern char* oppc_file_names[OPPC_MAX_FILES];
84
85 /* Macro for sending events to UI - meanwhile, trace message to PCO Viewer */
86 extern int vsi_o_state_ttrace ( const char * const format, ... );
87 #define UI_DISPLAY(s) vsi_o_state_ttrace s
88
89 /********************************************************************************
90 *
91 * Constants
92 *
93 *******************************************************************************/
94
95
96 /*******************************************************************************
97 *
98 * Macro definitions
99 *
100 ******************************************************************************/
101 #define OPPCA_BUFF_MAX (1 * 512)
102
103 #define BTL_CONFIG_OPP_MAX_FILE_NAME_LEN min(GOEP_MAX_UNICODE_LEN/2-2, BTHAL_FS_MAX_FILE_NAME_LENGTH)
104
105
106 #define OPPCA_CHECK_FS_NAME_LEN(fsPath) \
107 (OS_StrLen(fsPath) < (BTL_CONFIG_OPP_MAX_FILE_NAME_LEN + BTHAL_FS_MAX_PATH_LENGTH + 1))
108
109
110
111
112
113 /*******************************************************************************
114 *
115 * OPPC External Function prototypes
116 *
117 ******************************************************************************/
118
119 void mfw_btips_oppcInit(void);
120 void mfw_btips_oppcDeinit(void);
121
122 void mfw_btips_oppcEncapsulatePush(const char *fsPushPath, BD_ADDR *bd_addr);
123 void mfw_btips_oppcEncapsulatePull(const char *fsPullPath, BD_ADDR *bd_addr);
124 void mfw_btips_oppcEncapsulateExchange(const char *fsPushPath, const char *fsPullPath, BD_ADDR *bd_addr);
125
126
127
128
129
130
131
132 /*-------------------------------------------------------------------------------
133 * OppcaCurrOperation type
134 *
135 * Defines the OPPCA current operation.
136 */
137 typedef U8 OppcaCurrOperation;
138
139 #define OPPCA_OPER_NONE 0x00
140 #define OPPCA_OPER_BASIC_PULL 0x01 /* Pull */
141 #define OPPCA_OPER_BASIC_PUSH 0x02 /* Push */
142 #define OPPCA_OPER_BASIC_EXCHANGE 0x03 /* Push-Pull */
143 #define OPPCA_OPER_ENC_PULL 0x04 /* Connect-Pull-Disconnect */
144 #define OPPCA_OPER_ENC_PUSH 0x05 /* Connect-Push-Disconnect */
145 #define OPPCA_OPER_ENC_EXCHANGE 0x06 /* Connect-Push-Pull-Disconnect */
146
147
148 /*-------------------------------------------------------------------------------
149 * OppcaState type
150 *
151 * Defines the OPPCA current state.
152 */
153 typedef U8 OppcaState;
154
155 #define OPPCA_IDLE 0x00 /* OBEX and Transport disconnected */
156 #define OPPCA_CONNECTING 0x01 /* OBEX connecting */
157 #define OPPCA_TP_CONNECTED 0x02 /* Transport connected */
158 #define OPPCA_CONNECTED 0x03 /* OBEX connected */
159 #define OPPCA_DISCONNECTING 0x04 /* OBEX disconnecting */
160 #define OPPCA_TP_DISCONNECTING 0x05 /* Transport disconnecting */
161 #define OPPCA_DISABLING 0x06 /* OBEX and Transport disabling */
162
163
164 typedef struct _OppcaData
165 {
166 OppcaState state;
167
168 BOOL isConnected;
169
170 BOOL operationOngoing;
171
172 BtSecurityLevel securityLevel;
173
174 BtlObjectLocation objLocation;
175
176 OppcaCurrOperation currOper;
177
178 /* Memory Objects */
179 char pushBuff[OPPCA_BUFF_MAX];
180 char pullBuff[OPPCA_BUFF_MAX];
181
182 } OppcaData;
183
184
185 /********************************************************************************
186 *
187 * Globals
188 *
189 *******************************************************************************/
190
191 static OppcaData oppClient;
192 static BtlOppcContext *oppcContext = 0;
193
194 static char ObPushName[BTL_CONFIG_OPP_MAX_FILE_NAME_LEN + 1] = {'\0'};
195 static char ObPullName[BTL_CONFIG_OPP_MAX_FILE_NAME_LEN + 1] = {'\0'};
196
197 extern char push_file_name[];
198
199 /*******************************************************************************
200 *
201 * Internal Function prototypes
202 *
203 ******************************************************************************/
204 static void btips_oppcCallback(const BtlOppcEvent *Event);
205
206 static const char *mfw_btips_oppcGoepOpName(GoepOperation Op);
207
208 static BOOL mfw_btips_oppcBuildPushObject(BtlObject *objToPush, const char *fsPath, char *buff);
209 static BOOL mfw_btips_oppcBuildPullObject(BtlObject *objToPull, const char *fsPath, char *buff);
210
211 static BOOL mfw_btips_oppcConvertToMemPushObject(BtlObject *obj, const char *fsPushPathh, char *buff);
212 static void mfw_btips_oppcSetFsPushObject(BtlObject *obj, const char *fsPushPath);
213 static void mfw_btips_oppcSetFsPullObject(BtlObject *obj, const char *fsPullPath);
214 static void mfw_btips_oppcSetMemPullObject(BtlObject *obj, const char *fsPullPath, char *buff);
215
216 /*---------------------------------------------------------------------------
217 * mfw_btips_oppcInit
218 *---------------------------------------------------------------------------
219 *
220 * Synopsis: Initialize the OBEX Client for the OPP application
221 * and the Object Store.
222 *
223 * Return: void
224 *
225 */
226 void mfw_btips_oppcInit(void)
227 {
228 BtStatus status;
229
230 oppClient.state = OPPCA_IDLE;
231 oppClient.isConnected = FALSE;
232 oppClient.operationOngoing = FALSE;
233 oppClient.securityLevel = BSL_NO_SECURITY;
234 oppClient.currOper = OPPCA_OPER_NONE;
235 oppClient.objLocation = BTL_OBJECT_LOCATION_FS;
236
237 status = BTL_OPPC_Create((BtlAppHandle *)0, btips_oppcCallback, &oppClient.securityLevel, &oppcContext);
238 TRACE_EVENT_P1("BTL_OPPC_Create() returned %s.",pBT_Status(status));
239
240 status = BTL_OPPC_Enable(oppcContext);
241 TRACE_EVENT_P1("BTL_OPPC_Enable() returned %s.",pBT_Status(status));
242 }
243
244
245 /*---------------------------------------------------------------------------
246 * mfw_btips_oppcDeinit
247 *---------------------------------------------------------------------------
248 *
249 * Synopsis: Deinitialize the OBEX Client protocol.
250 *
251 * Return: void
252 *
253 */
254 void mfw_btips_oppcDeinit(void)
255 {
256 BtStatus status;
257
258 status = BTL_OPPC_Disable(oppcContext);
259
260 Report(("BTL_OPPC_Disable() returned %s.",pBT_Status(status)));
261
262 if (status == BT_STATUS_SUCCESS)
263 {
264 status = BTL_OPPC_Destroy(&oppcContext);
265
266 Report(("BTL_OPPC_Destroy() returned %s.", pBT_Status(status)));
267
268 oppClient.state = OPPCA_IDLE;
269 oppClient.isConnected = FALSE;
270 oppClient.operationOngoing = FALSE;
271 }
272 else
273 {
274 oppClient.state = OPPCA_DISABLING;
275 }
276 }
277
278
279 /*---------------------------------------------------------------------------
280 * mfw_btips_oppcEncapsulatePush
281 *---------------------------------------------------------------------------
282 *
283 * Synopsis: Initiate an OBEX Object Push procedure.
284 * Includes Connect and Disconnect from the opp server.
285 * If the given BD_ADDR is NULL, a search is performed.
286 *
287 * Return: void
288 *
289 */
290 void mfw_btips_oppcEncapsulatePush(const char *fsPushPath, BD_ADDR *bd_addr)
291 {
292 BtStatus status;
293 BtlObject objToPush;
294
295 Report(("mfw_btips_oppcEncapsulatePush: fsPushPath = %s", fsPushPath));
296
297 if (TRUE != OPPCA_CHECK_FS_NAME_LEN(fsPushPath))
298 {
299 Report(("mfw_btips_oppcEncapsulatePush: Can't push. fsPushPath too long"));
300 return;
301 }
302
303 if (TRUE != mfw_btips_oppcBuildPushObject(&objToPush, fsPushPath, oppClient.pushBuff))
304 {
305 Report(("OPPCA_BasicPull: Can't pull"));
306 return;
307 }
308
309 status = BTL_OPPC_ConnectPushDisconnect(oppcContext, bd_addr, &objToPush);
310
311 Report(("BTL_OPPC_ConnectPushDisconnect() returned %s.", pBT_Status(status)));
312 if (status == OB_STATUS_PENDING)
313 {
314 Report(("mfw_btips_oppcEncapsulatePush(): Started ..."));
315 oppClient.operationOngoing = TRUE;
316 oppClient.currOper = OPPCA_OPER_ENC_PUSH;
317 }
318 }
319
320
321 /*---------------------------------------------------------------------------
322 * mfw_btips_oppcEncapsulatePull
323 *---------------------------------------------------------------------------
324 *
325 * Synopsis: Initiate an OBEX Business Card Pull procedure.
326 * Includes Connect and Disconnect from the opp server.
327 * If the given BD_ADDR is NULL, a search is performed.
328 *
329 * Return: void
330 *
331 */
332 void mfw_btips_oppcEncapsulatePull(const char *fsPullPath, BD_ADDR *bd_addr)
333 {
334 BtStatus status;
335 BtlObject objToPull;
336
337 Report(("mfw_btips_oppcEncapsulatePull: fsPullPath = %s", fsPullPath));
338
339 if (TRUE != OPPCA_CHECK_FS_NAME_LEN(fsPullPath))
340 {
341 Report(("mfw_btips_oppcEncapsulatePull: Can't pull. fsPullPath too long"));
342 return;
343 }
344
345 if (TRUE != mfw_btips_oppcBuildPullObject(&objToPull, fsPullPath, oppClient.pullBuff))
346 {
347 Report(("mfw_btips_oppcEncapsulatePull: Can't pull"));
348 return;
349 }
350
351 status = BTL_OPPC_ConnectPullDisconnect(oppcContext, bd_addr, &objToPull);
352
353 Report(("BTL_OPPC_Pull() returned %s.", pBT_Status(status)));
354
355 if (status == OB_STATUS_PENDING)
356 {
357 Report(("mfw_btips_oppcEncapsulatePull(): Started ..."));
358 oppClient.operationOngoing = TRUE;
359 oppClient.currOper = OPPCA_OPER_ENC_PULL;
360 }
361 }
362
363
364 /*---------------------------------------------------------------------------
365 * mfw_btips_oppcEncapsulateExchange
366 *---------------------------------------------------------------------------
367 *
368 * Synopsis: Initiate an OBEX Business Card Exchange procedure.
369 * Includes Connect and Disconnect from the opp server.
370 * If the given BD_ADDR is NULL, a search is performed.
371 *
372 * Return: void
373 *
374 */
375 void mfw_btips_oppcEncapsulateExchange(const char *fsPushPath, const char *fsPullPath, BD_ADDR *bd_addr)
376 {
377 BtStatus status;
378 BtlObject objToPush, objToPull;
379
380 Report(("mfw_btips_oppcEncapsulateExchange: fsPushPath = %s, fsPullPath = %s", fsPushPath, fsPullPath));
381
382
383 /* -------- Push Operation --------- */
384
385 if (TRUE != OPPCA_CHECK_FS_NAME_LEN(fsPushPath))
386 {
387 Report(("mfw_btips_oppcEncapsulateExchange: Can't push. fsPushath too long"));
388 return;
389 }
390
391 if (TRUE != mfw_btips_oppcBuildPushObject(&objToPush, fsPushPath, oppClient.pushBuff))
392 {
393 Report(("mfw_btips_oppcEncapsulateExchange: Can't push"));
394 return;
395 }
396
397 /* -------- Pull Operation --------- */
398
399 if (TRUE != OPPCA_CHECK_FS_NAME_LEN(fsPullPath))
400 {
401 Report(("mfw_btips_oppcEncapsulateExchange: Can't pull. fsPullPath too long"));
402 return;
403 }
404
405 if (TRUE != mfw_btips_oppcBuildPullObject(&objToPull, fsPullPath, oppClient.pullBuff))
406 {
407 Report(("mfw_btips_oppcEncapsulateExchange: Can't pull"));
408 return;
409 }
410
411
412 status = BTL_OPPC_ConnectExchangeDisconnect(oppcContext, bd_addr, &objToPush, &objToPull);
413
414 Report(("BTL_OPPC_ConnectExchangeDisconnect() returned %s.", pBT_Status(status)));
415
416 if (status == OB_STATUS_PENDING)
417 {
418 Report(("mfw_btips_oppcEncapsulateExchange(): Started ..."));
419 oppClient.operationOngoing = TRUE;
420 oppClient.currOper = OPPCA_OPER_ENC_EXCHANGE;
421 }
422 }
423
424
425 /*---------------------------------------------------------------------------
426 * btips_oppcCallback
427 *---------------------------------------------------------------------------
428 *
429 * Synopsis: This function processes OBEX Client protocol events.
430 *
431 * Return: void
432 *
433 */
434 static void btips_oppcCallback(const BtlOppcEvent *Event)
435 {
436 BD_ADDR bdAddr;
437 char addr[BDADDR_NTOA_SIZE];
438 BtStatus status;
439
440 switch (Event->oppcEvent->event)
441 {
442 case OPPC_EVENT_COMPLETE:
443
444 TRACE_EVENT_P1("btips_oppcCallback: The current %s is complete.", mfw_btips_oppcGoepOpName(Event->oppcEvent->oper));
445
446 switch (Event->oppcEvent->oper)
447 {
448 case GOEP_OPER_CONNECT:
449 TRACE_EVENT_P1("btips_oppcCallback: Transport Connection has been established with %s", bdaddr_ntoa(&bdAddr, addr));
450 BTL_OPPC_GetConnectedDevice(oppcContext, &bdAddr);
451 oppClient.state = OPPCA_CONNECTED;
452 oppClient.isConnected = TRUE;
453 break;
454
455 case GOEP_OPER_DISCONNECT:
456 TRACE_EVENT("btips_oppcCallback: Transport Connection has been disconnected.");
457 oppClient.isConnected = FALSE;
458 oppClient.state = OPPCA_IDLE;
459 oppClient.operationOngoing = FALSE;
460 break;
461
462
463 case GOEP_OPER_PULL:
464
465 switch(oppClient.currOper)
466 {
467 case OPPCA_OPER_BASIC_PULL:
468 oppClient.operationOngoing = FALSE;
469 break;
470
471 case OPPCA_OPER_BASIC_EXCHANGE:
472 oppClient.operationOngoing = FALSE;
473 break;
474 }
475
476 break;
477
478
479 case GOEP_OPER_PUSH:
480
481 switch(oppClient.currOper)
482 {
483 case OPPCA_OPER_BASIC_PUSH:
484 oppClient.operationOngoing = FALSE;
485 break;
486 }
487 break;
488 }
489 break;
490
491 case OPPC_EVENT_ABORTED:
492
493 UI_DISPLAY(("btips_oppcCallback: %s operation failed.", mfw_btips_oppcGoepOpName(Event->oppcEvent->oper)));
494 break;
495
496 case OPPC_EVENT_TP_CONNECTED:
497
498 BTL_OPPC_GetConnectedDevice(oppcContext, &bdAddr);
499 UI_DISPLAY(("btips_oppcCallback: Transport Connection is up to %s.", bdaddr_ntoa(&bdAddr, addr)));
500
501 oppClient.state = OPPCA_TP_CONNECTED;
502 oppClient.isConnected = TRUE;
503 break;
504
505 case OPPC_EVENT_TP_DISCONNECTED:
506
507 UI_DISPLAY(("btips_oppcCallback: Transport Connection has been disconnected."));
508
509
510 oppClient.isConnected = FALSE;
511 oppClient.operationOngoing = FALSE;
512
513 if (oppClient.state != OPPCA_DISABLING)
514 {
515 oppClient.state = OPPCA_IDLE;
516 }
517 break;
518
519
520 case OPPC_EVENT_DISCOVERY_FAILED:
521
522 UI_DISPLAY(("btips_oppcCallback: Discovery Failure."));
523 oppClient.state = OPPCA_IDLE;
524 break;
525
526 case OPPC_EVENT_NO_SERVICE_FOUND:
527
528 UI_DISPLAY(("btips_oppcCallback: No OBEX Service Found."));
529 oppClient.state = OPPCA_IDLE;
530 break;
531
532
533 case OPPC_EVENT_OBJECT_PROGRESS:
534
535 UI_DISPLAY(("btips_oppcCallback: progress bar ..."));
536
537 break;
538
539
540 case OPPC_EVENT_DISABLED:
541
542 UI_DISPLAY(("btips_oppcCallback: Receiving OPPC_EVENT_DISABLED."));
543
544 if (OPPCA_DISABLING == oppClient.state)
545 {
546 status = BTL_OPPC_Destroy(&oppcContext);
547
548 Report(("BTL_OPPC_Destroy() returned %s.", pBT_Status(status)));
549 }
550
551 oppClient.state = OPPCA_IDLE;
552 break;
553
554 default:
555
556 UI_DISPLAY(("btips_oppcCallback: Unexpected event: %i", Event->oppcEvent->event));
557 break;
558 }
559 }
560
561
562 /*---------------------------------------------------------------------------
563 * mfw_btips_oppcGoepOpName
564 *---------------------------------------------------------------------------
565 *
566 * Synopsis: Return a pointer to the name of the current operation.
567 *
568 * Return: ASCII String pointer.
569 *
570 */
571 static const char *mfw_btips_oppcGoepOpName(GoepOperation Op)
572 {
573 switch (Op)
574 {
575 case GOEP_OPER_PUSH:
576 return "Push";
577 case GOEP_OPER_PULL:
578 return "Pull";
579 case GOEP_OPER_CONNECT:
580 return "Connect";
581 case GOEP_OPER_DISCONNECT:
582 return "Disconnect";
583 case GOEP_OPER_ABORT:
584 return "Abort";
585 case GOEP_OPER_DELETE:
586 return "Delete";
587 case GOEP_OPER_SETFOLDER:
588 return "Set Folder";
589 }
590 return "Unknown";
591 }
592
593
594 /*---------------------------------------------------------------------------
595 * mfw_btips_oppcBuildPushObject()
596 *
597 * Synopsis: Build push object
598 *
599 * Return: TRUE - success FALSE - failed
600 *
601 */
602 static BOOL mfw_btips_oppcBuildPushObject(BtlObject *objToPush, const char *fsPath, char *buff)
603 {
604 if (oppClient.objLocation == BTL_OBJECT_LOCATION_MEM)
605 {
606 if (TRUE != mfw_btips_oppcConvertToMemPushObject(objToPush, fsPath, buff))
607 {
608 return FALSE;
609 }
610 }
611 else if (oppClient.objLocation == BTL_OBJECT_LOCATION_FS)
612 {
613 mfw_btips_oppcSetFsPushObject(objToPush, fsPath);
614 }
615
616 return TRUE;
617 }
618
619
620 /*---------------------------------------------------------------------------
621 * mfw_btips_oppcBuildPullObject()
622 *
623 * Synopsis: Build push object
624 *
625 * Return: TRUE - success FALSE - failed
626 *
627 */
628 static BOOL mfw_btips_oppcBuildPullObject(BtlObject *objToPull, const char *fsPath, char *buff)
629 {
630 if (oppClient.objLocation == BTL_OBJECT_LOCATION_MEM)
631 {
632 mfw_btips_oppcSetMemPullObject(objToPull, fsPath, buff);
633 }
634 else if (oppClient.objLocation == BTL_OBJECT_LOCATION_FS)
635 {
636 mfw_btips_oppcSetFsPullObject(objToPull, fsPath);
637 }
638
639 return TRUE;
640 }
641
642
643 /*---------------------------------------------------------------------------
644 * mfw_btips_oppcConvertToMemPushObject()
645 *
646 * Synopsis: Function for testing OPP from memory objects. Convert file object to memory object by reading the
647 * file and modifying proper fileds uses a static buffer, so only one such object can be supported at a time
648 * maximum file size is 512 KB
649 *
650 * Return: void
651 *
652 */
653 static BOOL mfw_btips_oppcConvertToMemPushObject(BtlObject *obj, const char *fsPushPath, char *buff)
654 {
655 BtFsStatus btFsStatus;
656 BthalFsFileDesc fd;
657 BTHAL_U32 numRead;
658 BthalFsStat FileStat;
659
660 btFsStatus = BTHAL_FS_Stat((const BTHAL_U8 *)fsPushPath, &FileStat);
661 if(btFsStatus != BT_STATUS_HAL_FS_SUCCESS)
662 {
663 Report(("Client: Error - File was not found %s", fsPushPath));
664 return FALSE;
665 }
666
667 if (FileStat.size > OPPCA_BUFF_MAX)
668 {
669 Report(("Client: Error pushed file > %d bytes", OPPCA_BUFF_MAX));
670 return FALSE;
671 }
672
673 btFsStatus = BTHAL_FS_Open((const BTHAL_U8 *)fsPushPath,
674 BTHAL_FS_O_RDONLY | BTHAL_FS_O_BINARY, /* Read Only */
675 (BthalFsFileDesc *)&fd);
676
677 if (btFsStatus == BT_STATUS_HAL_FS_SUCCESS)
678 {
679 btFsStatus = BTHAL_FS_Read(fd, oppClient.pushBuff, OPPCA_BUFF_MAX, &numRead);
680
681 if (btFsStatus == BT_STATUS_HAL_FS_SUCCESS)
682 {
683 Report(("Client: fsPushPath = %s, numRead = %d", fsPushPath, numRead));
684 }
685
686 BTHAL_FS_Close(fd);
687
688 /* Extract object name from fsPath */
689 OBSTORE_ExtractObjName(fsPushPath, ObPushName);
690
691 obj->objectLocation = BTL_OBJECT_LOCATION_MEM;
692 obj->objectName = ObPushName;
693 obj->location.memLocation.memAddr = buff;
694 obj->location.memLocation.size = numRead;
695 obj->objectMimeType = "text/x-vCard";
696 }
697 else
698 {
699 Report(("Client: Error - could not open %s", fsPushPath));
700 return FALSE;
701 }
702
703 return TRUE;
704 }
705
706
707 /*---------------------------------------------------------------------------
708 * mfw_btips_oppcSetMemPullObject()
709 *
710 * Synopsis: Function for testing OPP from memory objects.
711 * Sets memory object fields prior to PULL operation
712 *
713 * Return: void
714 *
715 */
716 static void mfw_btips_oppcSetMemPullObject(BtlObject *obj, const char *fsPullPath, char *buff)
717 {
718 OBSTORE_ExtractObjName(fsPullPath, ObPullName);
719
720 obj->objectLocation = BTL_OBJECT_LOCATION_MEM;
721
722 obj->location.fsLocation.fsPath = NULL;
723 obj->location.memLocation.memAddr = buff;
724 obj->location.memLocation.size = OPPCA_BUFF_MAX;
725
726 obj->objectMimeType = "text/x-vCard";;
727 obj->objectName = ObPullName;
728 }
729
730
731 /*---------------------------------------------------------------------------
732 * mfw_btips_oppcSetFsPushObject()
733 *
734 * Synopsis: Function for testing OPP from FS Push objects.
735 *
736 * Return: void
737 *
738 */
739 static void mfw_btips_oppcSetFsPushObject(BtlObject *obj, const char *fsPushPath)
740 {
741 OBSTORE_ExtractObjName(fsPushPath, ObPushName);
742
743 obj->objectName = ObPushName;
744 obj->location.fsLocation.fsPath = fsPushPath;
745
746 /* This should be provided by the user (i.e. this is just an example) */
747 obj->objectMimeType = "text/x-vCard";
748 obj->objectLocation = BTL_OBJECT_LOCATION_FS;
749 }
750
751
752 /*---------------------------------------------------------------------------
753 * mfw_btips_oppcSetFsPullObject()
754 *
755 * Synopsis: Function for testing OPP from FS Pull objects.
756 *
757 * Return: void
758 *
759 */
760 static void mfw_btips_oppcSetFsPullObject(BtlObject *obj, const char *fsPullPath)
761 {
762 OBSTORE_ExtractObjName(fsPullPath, ObPullName);
763
764 obj->objectName = ObPullName;
765 obj->location.fsLocation.fsPath = fsPullPath;
766 obj->objectMimeType = "text/x-vCard";
767 obj->objectLocation = BTL_OBJECT_LOCATION_FS;
768 }
769
770 /*---------------------------------------------------------------------------
771 * mfw_btips_oppcCallback
772 *---------------------------------------------------------------------------
773 *
774 * Synopsis: This function processes OBEX client protocol events.
775 *
776 * Return: void
777 *
778 */
779 void mfw_btips_oppcCallback(T_BTIPS_MMI_IND *para)
780 {
781
782 }
783
784 /*******************************************************************************
785
786 $Function: mfw_btips_oppcPopulateFiles
787
788 $Description:Populates file names into the array
789
790 $Returns: The count of the files in the directory
791
792 $Arguments: file_names:Pointer to the arrayto store file names
793 max_files_count:Max file counts to be stored in array
794 *******************************************************************************/
795 int mfw_btips_oppcPopulateFiles(char **file_names, int max_files_count,char* dir_name_p)
796 {
797
798 T_FFS_DIR dir = {0};
799 char dest_name_p[100] = "";
800 int i, files_count = 0;
801 char *fileExt;
802
803 TRACE_FUNCTION_P1("mfw_btips_oppcPopulateFiles from directory %s", dir_name_p);
804
805 if (ffs_opendir (dir_name_p, &dir) <= 0)
806 {
807 TRACE_ERROR("Could not open Dir");
808
809 files_count = 0;
810 }
811 //Release previous allocated memory before allocating again
812 mfw_btips_oppcUnpopulateFiles(file_names);
813 //read the file names
814 //file_count will be used to populate the array index
815 for (i = 0; ffs_readdir (&dir, dest_name_p, 100) > 0x0; i++)
816 {
817 if((strcmp(dest_name_p, ".") == 0) || (strcmp(dest_name_p, "..") == 0))
818 continue;
819 TRACE_FUNCTION_P1("Reading Dir - %s",dest_name_p);
820 (file_names[files_count]) = (char*)mfwAlloc(strlen(dest_name_p) + 1);
821 if(file_names[files_count] != NULL)
822 {
823 #if 0
824 //Retrieve file extension.Store only the supported file formats in array
825 fileExt =mfw_btips_oppcGetExtension(dest_name_p);
826 //List the MP3 files also.Mp3 files hsould not be listed or ULC
827 if ( (strcmp(fileExt, "mp3") == 0))
828 {
829 strcpy (file_names[files_count], dest_name_p);
830 files_count++;
831 }
832 else if ( (strcmp(fileExt, "wav")== 0))
833 {
834 strcpy (file_names[files_count], dest_name_p);
835 files_count++;
836 }
837 else if ( (strcmp(fileExt, "pcm")== 0))
838 {
839 strcpy (file_names[files_count], dest_name_p);
840 files_count++;
841 }
842 else if(files_count >= max_files_count)
843 break;
844 #endif
845 strcpy (file_names[files_count], dest_name_p);
846 TRACE_FUNCTION_P1("file_names - %s", file_names[files_count]);
847 files_count++;
848 if(files_count >= max_files_count)
849 break;
850 }
851 else
852 {
853 //files_count = 0;
854 }
855
856 }
857 //Closing the directory aa per the new FFS logic
858 ffs_closedir(dir);
859
860 TRACE_EVENT_P1("read files_count is %d",files_count);
861 TRACE_FUNCTION_P1("read files_count is %d",files_count);
862 return files_count;
863 }
864 /*******************************************************************************
865
866 $Function: mfw_btips_oppcUnpopulateFiles
867
868 $Description:Frees the memory allocated for the array
869 $Returns: None
870
871 $Arguments: file_names:Pointer to the arrayto store file names
872
873 *******************************************************************************/
874 void mfw_btips_oppcUnpopulateFiles(char **file_names)
875 {
876 int i;
877 TRACE_FUNCTION("mfw_btips_oppcUnpopulateFiles");
878 mfw_BtipsReport("mfw_btips_oppcUnpopulateFiles");
879
880 //Free the allocated memory for file names
881 for (i = 0; i<OPPC_MAX_FILES; i++)
882 {
883 if(file_names[i])
884 {
885 mfwFree((U8 *)file_names[i],(U16)strlen(file_names[i]) + 1);
886 }
887 file_names[i]=NULL;
888 }
889
890 }
891
892 /*******************************************************************************
893
894 $Function: mfw_btips_oppcGetExtension
895
896 $Description: public function to retrieve the extension of a file
897
898 $Returns:Extention of the filename
899
900 $Arguments: scr- Filename
901
902 *******************************************************************************/
903 char *mfw_btips_oppcGetExtension(char *src)
904 {
905 int i,len;
906
907 TRACE_FUNCTION("mfw_btips_oppcGetExtension");
908 mfw_BtipsReport("mfw_btips_oppcGetExtension");
909 len = strlen(src);
910 for(i = 0; i < len; i++){
911 if(src[i] == '.'){
912 return (src+i+1);
913 }
914 }
915 return (src+i);
916 }
917 /*******************************************************************************
918
919 $Function: mfw_btips_oppcGetNumFiles
920
921 $Description: returns the file count
922
923 $Returns: Count of the Midi files
924
925 $Arguments: None
926
927 *******************************************************************************/
928 int mfw_btips_oppcGetNumFiles(void)
929 {
930 TRACE_FUNCTION_P1("mfw_btips_oppcGetNumFiles -oppc_files_count - %d", oppc_files_count);
931 if(oppc_files_count<=0)
932 return 0;
933 else
934 return oppc_files_count;
935
936 }
937 /*******************************************************************************
938
939 $Function: mfw_btips_oppcGetFileName
940
941 $Description: Returns the file name
942
943 $Returns: Name of the file
944
945 $Arguments: index:The index of the file, whose name has to be retrieved
946
947 *******************************************************************************/
948
949 char* mfw_btips_oppcGetFileName(UBYTE index)
950 {
951
952 TRACE_FUNCTION_P2("oppc_file_names[%d] is %s",index,(char *)oppc_file_names[index]);
953 return (char *) oppc_file_names[index];
954 }
955 /*******************************************************************************
956
957 $Function: mfw_btips_oppcGetConnectDevice
958
959 $Description: Returns the TRUE when succeeds
960 $Returns: TRUE or FALSE
961
962 $Arguments:
963
964 *******************************************************************************/
965
966 BOOL mfw_btips_oppcGetConnectedDevice (BD_ADDR *bdAddr, U8 *name)
967 {
968 BtStatus status;
969 char bdaddrstring[BDADDR_NTOA_SIZE];
970
971 status = BTL_OPPC_GetConnectedDevice (oppcContext, bdAddr);
972 bdaddr_ntoa(bdAddr,bdaddrstring);
973 TRACE_FUNCTION_P1("mfw_btips_ftpsGetConnectDevice OPPC %s ",bdaddrstring);
974
975 if (status == BT_STATUS_SUCCESS)
976 {
977 mfw_btips_bmgGetDeviceName (bdAddr, name);
978 TRACE_FUNCTION_P1("mfw_btips_oppcGetConnectDevice OPPC name %s ",name);
979 return TRUE;
980 }
981 return FALSE;
982 }
983
984 void mfw_btips_oppc_Disconnect(void)
985 {
986 BtStatus status;
987
988 if (oppClient.isConnected == TRUE)
989 {
990 status = BTL_OPPC_Disconnect(oppcContext);
991 Report(("BTL_OPPC_Disconnect() returned %s.", pBT_Status(status)));
992 }
993 else
994 {
995 Report(("mfw_btips_oppc_Disconnect: Client is not connected!"));
996 }
997 }
998
999
1000 #endif
1001