comparison src/ui3/mfw/mfw_BtipsFtps.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_Btips.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 BTIPS FTP Server APPlication functionality.
22
23 ********************************************************************************
24 $History: Mfw_BtipsFtps.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
66 #include "osapi.h"
67
68 /* GPF Includes */
69 #include "typedefs.h"
70 #include "vsi.h"
71 //#include "../p_btt.h"
72
73 #if BT_STACK == XA_ENABLED
74 #include <me.h>
75 #include <bttypes.h>
76 #include <sec.h>
77 #endif
78
79 #include "btl_common.h"
80 #include "btl_bmg.h"
81 #include "debug.h"
82
83 #include "goep.h"
84 #include "ftp.h"
85
86 /* BTL inclides */
87 #include "btl_ftps.h"
88
89 #include "bthal_fs.h"
90
91 #include "mfw_mfw.h"
92 #include "mfw_win.h"
93 #include "mfw_icn.h" /* included for mfw_mnu.h */
94 #include "mfw_mnu.h"
95 #include "mfw_tim.h"
96 #include "mfw_kbd.h"
97 #include "mfw_sat.h" /* included for MmiDummy.h, included for MmiMenu.h */
98
99 #include "Mfw_Btips.h"
100 #include "Mfw_BtipsBmg.h"
101
102 /* Internal Global variables for FTP Server*/
103 static BtlFtpsContext *ftpsContext = 0;
104 static BtSecurityLevel securityLevel = BSL_NO_SECURITY;
105 static BD_ADDR bdAddr;
106
107
108 /****************************************************************************
109 *
110 * Internal Function prototypes
111 *
112 ***************************************************************************/
113 static void btips_ftpsCallBack(const BtlFtpsEvent *event);
114 #ifdef WIN32
115 const char *pBT_Status(I8 Status);
116 #else
117 static const char *pBT_Status(I8 Status);
118 #endif
119 static const char *GoepOpName(GoepOperation Op);
120
121
122 /****************************************************************************
123 *
124 * RAM data
125 *
126 ****************************************************************************/
127
128 #if OBEX_AUTHENTICATION == XA_ENABLED
129 static char realm[20]; /* OBEX realm */
130 static char password[20]; /* OBEX Authentication password */
131 static char userId[20]; /* OBEX Authentication userId */
132 #endif /* OBEX_AUTHENTICATION == XA_ENABLED */
133
134 static char rootPath[80];
135 static BtlFtpsObjectRequestMask objectRequestMask;
136 static BOOL accept;
137 char BTStr[20];
138 /*---------------------------------------------------------------------------
139 * mfw_btips_ftpsInit
140 *---------------------------------------------------------------------------
141 *
142 * Synopsis: Create and Enable the FTP Server .
143 *
144 * Return: void
145 *
146 */
147
148 void mfw_btips_ftpsInit (void)
149 {
150 BtStatus status;
151
152 OS_StrCpy(realm, "MyRealm");
153 OS_StrCpy(password, "MyPassword");
154 OS_StrCpy(userId, "MyUserId");
155
156 OS_StrCpy(rootPath, "/");
157
158 status = BTL_FTPS_Create ((BtlAppHandle *) 0, btips_ftpsCallBack,
159 &securityLevel, &ftpsContext);
160
161 Report(("BTL_FTPS_Create() returned %s.",pBT_Status(status)));
162
163 OS_StrCpy (rootPath, BT_DEMO_FOLDER_PATH);
164
165 status = BTL_FTPS_Enable(ftpsContext, 0, rootPath);
166
167 Report(("BTL_FTPS_Enable() returned %s.",pBT_Status(status)));
168
169 status = BTL_FTPS_ConfigObjectRequest ( ftpsContext,
170 BTL_FTPS_OBJECT_REQUEST_PUSH |
171 BTL_FTPS_OBJECT_REQUEST_PULL |
172 BTL_FTPS_OBJECT_REQUEST_DELETE );
173
174 Report(("BTL_FTPS_ConfigObjectRequest() returned %s.",pBT_Status(status)));
175
176 }
177
178 /*---------------------------------------------------------------------------
179 * mfw_btips_ftpsAbort
180 *---------------------------------------------------------------------------
181 *
182 * Synopsis: Requests the current operation be aborted.
183 *
184 * Return: void
185 *
186 */
187 void mfw_btips_ftpsAbort(void)
188 {
189 BtStatus status;
190
191 status = BTL_FTPS_Abort(ftpsContext, OBRC_CONFLICT);
192
193 Report(("BTL_FTPS_Abort() returned %s.",pBT_Status(status)));
194
195 }
196
197 /*---------------------------------------------------------------------------
198 * mfw_btips_ftpsAcceptObjectRequest
199 *---------------------------------------------------------------------------
200 *
201 * Synopsis: This function must be called after receiving object request from the client,
202 * in order to accept or reject the request.
203 *
204 * Return: BOOL
205 *
206 */
207 void mfw_btips_ftpsAcceptObjectRequest (BOOL flag)
208 {
209 BtStatus status;
210
211 status = BTL_FTPS_AcceptObjectRequest (ftpsContext, flag);
212
213 Report(("BTL_FTPS_AcceptObjectRequest() returned %s.", pBT_Status(status)));
214 }
215
216 /*---------------------------------------------------------------------------
217 * mfw_btips_ftpsSetSecurityLevel
218 *---------------------------------------------------------------------------
219 *
220 * Synopsis: Sets security level for the given FTPS context.
221 *
222 * Return: TRUE if security level is ON, else FALSE.
223 *
224 */
225 BOOL mfw_btips_ftpsSetSecurityLevel (void)
226 {
227 BtStatus status;
228 BtSecurityLevel newSecurityLevel = securityLevel;
229
230 status = BTL_FTPS_SetSecurityLevel (ftpsContext, &newSecurityLevel);
231
232 Report(("BTL_FTPS_SetSecurityLevel() returned %s.", pBT_Status(status)));
233
234 return TRUE;
235 }
236
237
238 #if OBEX_AUTHENTICATION == XA_ENABLED
239 /*---------------------------------------------------------------------------
240 * mfw_btips_ftpsObexAuthenticationResponse
241 *---------------------------------------------------------------------------
242 *
243 * Synopsis: Responde to OBEX auth.
244 *
245 * Return: void
246 *
247 */
248 BOOL mfw_btips_ftpsObexAuthenticationResponse (void)
249 {
250 BtStatus status;
251
252 status = BTL_FTPS_ObexAuthenticationResponse (ftpsContext, userId, password);
253
254 Report(("BTL_FTPS_ObexAuthenticationResponse() returned %s.",pBT_Status(status)));
255
256 return ((status == BT_STATUS_SUCCESS) ? (TRUE) : (FALSE));
257 }
258 #endif /* OBEX_AUTHENTICATION == XA_ENABLED */
259
260 BOOL mfw_btips_ftpsGetConnectedDevice (BD_ADDR *bdAddr, U8 *name)
261 {
262 BtStatus status;
263
264 status = BTL_FTPS_GetConnectedDevice (ftpsContext, bdAddr);
265
266 if (status == BT_STATUS_SUCCESS)
267 {
268 mfw_btips_bmgGetDeviceName (bdAddr, name);
269 return TRUE;
270 }
271 return FALSE;
272 }
273
274 void mfw_btips_ftpsDisconnect (void)
275 {
276 BTL_FTPS_Disconnect (ftpsContext);
277 }
278
279
280 /*---------------------------------------------------------------------------
281 * btips_ftpsCallBack
282 *---------------------------------------------------------------------------
283 *
284 * Synopsis: This function processes FTP Events received from BTL, only events requested in BTL_FTPS_ConfigObjectRequest
285 * will be received
286 * Return: void
287 *
288 */
289 static void btips_ftpsCallBack(const BtlFtpsEvent *event)
290 {
291 char addr[BDADDR_NTOA_SIZE];
292 T_BTIPS_MMI_IND btips_mmi_ind;
293 BtlBmgDeviceRecord record;
294 BtStatus status;
295
296 TRACE_FUNCTION_P1("btips_ftpsCallback %d", event->ftpsEvent->event);
297
298 btips_mmi_ind.mfwBtipsEventType = MFW_BTIPS_FTPS_EVENT;
299
300
301 /* First process only events that are not "object" related. */
302 switch ( event->ftpsEvent->event)
303 {
304 case FTPS_EVENT_TP_CONNECTED:
305 BTL_FTPS_GetConnectedDevice(ftpsContext, &bdAddr);
306 TRACE_FUNCTION_P1("FTP Server: Transport Connection is up to %s.", bdaddr_ntoa(&bdAddr, addr));
307 break;
308
309 case FTPS_EVENT_TP_DISCONNECTED:
310 TRACE_FUNCTION(("FTP Server: Transport Connection has been disconnected."));
311 break;
312
313 #if OBEX_AUTHENTICATION == XA_ENABLED
314
315 case FTPS_EVENT_AUTH_CHALLENGE:
316 TRACE_FUNCTION_P1("FTP Server: Received Authenticate Challenge for %s operation.",
317 GoepOpName(event->ftpsEvent->oper));
318 #if OBEX_MAX_REALM_LEN > 0
319 Report(("FTP Server: Realm: %s, charset %d , Options %d.",
320 event->ftpsEvent->info.challenge.realm+1, event->ftpsEvent->info.challenge.realm[0], event->ftpsEvent->info.challenge.options));
321 #endif /* OBEX_MAX_REALM_LEN > 0 */
322
323 mfw_btips_ftpsObexAuthenticationResponse ( );
324 break;
325
326 #endif /* OBEX_AUTHENTICATION == XA_ENABLED */
327
328 case FTPS_EVENT_START:
329 TRACE_FUNCTION_P1("FTP Server: Receiving a %s operation.", GoepOpName(event->ftpsEvent->oper));
330 break;
331
332 case FTPS_EVENT_ABORTED:
333 TRACE_FUNCTION_P1("FTPServer: %s operation aborted.", GoepOpName(event->ftpsEvent->oper));
334 btips_mmi_ind.data.ftpsBtEvent.event = MFW_BTIPS_FTPS_ABORTED_EVENT;
335 btipsNotifyMFW(&btips_mmi_ind);
336 break;
337
338 case FTPS_EVENT_COMPLETE:
339 TRACE_FUNCTION_P1("FTPServer: %s operation complete.", GoepOpName(event->ftpsEvent->oper));
340 switch(event->ftpsEvent->oper)
341 {
342 case GOEP_OPER_PUSH:
343 btips_mmi_ind.data.ftpsBtEvent.event = MFW_BTIPS_FTPS_PUT_COMP_EVENT;
344 break;
345 case GOEP_OPER_DELETE:
346 btips_mmi_ind.data.ftpsBtEvent.event = MFW_BTIPS_FTPS_DELETE_COMP_EVENT;
347 break;
348 case GOEP_OPER_CONNECT:
349 btips_mmi_ind.data.ftpsBtEvent.event = MFW_BTIPS_FTPS_CONNECT_EVENT;
350 break;
351 case GOEP_OPER_DISCONNECT:
352 btips_mmi_ind.data.ftpsBtEvent.event = MFW_BTIPS_FTPS_DISCONNECT_EVENT;
353 break;
354 }
355 btipsNotifyMFW(&btips_mmi_ind);
356 break;
357
358 case FTPS_EVENT_OBJECT_PROGRESS:
359 Report(("FTPServer: %d percent of progress was complete.",
360 (event->ftpsEvent->info.progress.currPos/event->ftpsEvent->info.progress.maxPos)*100));
361 break;
362
363 case FTPS_EVENT_OBJECT_REQUEST:
364 Report(("FTP Object request : operation \"%s\".", GoepOpName(event->ftpsEvent->oper)));
365 Report(("FTP Object request: name \"%s\".", event->ftpsEvent->info.request.name));
366 Report(("FTP Object request: length \"%d\".", event->ftpsEvent->info.request.objectLen));
367 TRACE_FUNCTION("FTP Please accept or reject!");
368
369 #if 0
370 status = BTL_BMG_DDB_FindRecord (bdAddr, &record);
371 if (status == BT_STATUS_SUCCESS)
372 {
373 #endif
374 if (event->ftpsEvent->oper == GOEP_OPER_PUSH)
375 {
376 btips_mmi_ind.data.ftpsBtEvent.event = MFW_BTIPS_FTPS_PUT_EVENT;
377 strcpy (btips_mmi_ind.data.ftpsBtEvent.p.ftpPutRequest.objectName, event->ftpsEvent->info.request.name);
378 // strcpy (btips_mmi_ind.data.ftpsBtEvent.p.ftpPutRequest.deviceName, record.name);
379 // btips_mmi_ind.data.ftpsBtEvent.p.ftpPutRequest.bdAddr = bdAddr;
380 mfw_btips_ftpsGetConnectedDevice (&(btips_mmi_ind.data.ftpsBtEvent.p.ftpPutRequest.bdAddr), btips_mmi_ind.data.ftpsBtEvent.p.ftpPutRequest.deviceName);
381 }
382 else if (event->ftpsEvent->oper == GOEP_OPER_PULL)
383 {
384 btips_mmi_ind.data.ftpsBtEvent.event = MFW_BTIPS_FTPS_GET_EVENT;
385 strcpy (btips_mmi_ind.data.ftpsBtEvent.p.ftpGetRequest.objectName, event->ftpsEvent->info.request.name);
386 // strcpy (btips_mmi_ind.data.ftpsBtEvent.p.ftpGetRequest.deviceName, record.name);
387 // btips_mmi_ind.data.ftpsBtEvent.p.ftpGetRequest.bdAddr = bdAddr;
388 mfw_btips_ftpsGetConnectedDevice (&(btips_mmi_ind.data.ftpsBtEvent.p.ftpGetRequest.bdAddr), btips_mmi_ind.data.ftpsBtEvent.p.ftpGetRequest.deviceName);
389 }
390 else if (event->ftpsEvent->oper == GOEP_OPER_DELETE)
391 {
392 btips_mmi_ind.data.ftpsBtEvent.event = MFW_BTIPS_FTPS_DELETE_EVENT;
393 strcpy (btips_mmi_ind.data.ftpsBtEvent.p.ftpDeleteRequest.objectName, event->ftpsEvent->info.request.name);
394 #if 0
395 strcpy (btips_mmi_ind.data.ftpsBtEvent.p.ftpDeleteRequest.deviceName, record.name);
396 btips_mmi_ind.data.ftpsBtEvent.p.ftpDeleteRequest.bdAddr = bdAddr;
397 #endif
398 mfw_btips_ftpsGetConnectedDevice (&(btips_mmi_ind.data.ftpsBtEvent.p.ftpDeleteRequest.bdAddr), btips_mmi_ind.data.ftpsBtEvent.p.ftpDeleteRequest.deviceName);
399 }
400 else
401 {
402 break;
403 }
404
405 btipsNotifyMFW(&btips_mmi_ind);
406 #if 0
407 }
408 #endif
409 break;
410 }
411 }
412
413 void mfw_btips_ftpsCallback(T_BTIPS_MMI_IND * mmiInd)
414 {
415 MfwBtFtpsEvent ftpsBtEvent = mmiInd->data.ftpsBtEvent;
416
417 TRACE_FUNCTION_P1("mfw_btips_ftpsCallback Event = %x", ftpsBtEvent.event);
418 switch(ftpsBtEvent.event)
419 {
420 case MFW_BTIPS_FTPS_PUT_EVENT:
421 mfw_btips_signal(E_BTIPS_FTPS_PUT_EVENT, mmiInd);
422 break;
423
424 case MFW_BTIPS_FTPS_GET_EVENT:
425 mfw_btips_signal(E_BTIPS_FTPS_GET_EVENT, mmiInd);
426 break;
427
428 case MFW_BTIPS_FTPS_DELETE_EVENT:
429 mfw_btips_signal(E_BTIPS_FTPS_DELETE_EVENT, mmiInd);
430 break;
431
432 case MFW_BTIPS_FTPS_COMPLETE_EVENT:
433 mfw_btips_signal(E_BTIPS_FTPS_COMPLETE_EVENT,mmiInd);
434 break;
435
436 case MFW_BTIPS_FTPS_ABORTED_EVENT:
437 mfw_btips_signal(E_BTIPS_FTPS_ABORTED_EVENT,mmiInd);
438 break;
439
440 case MFW_BTIPS_FTPS_CONNECT_EVENT:
441 mfw_btips_signal(E_BTIPS_FTPS_CONNECT_EVENT,mmiInd);
442 break;
443
444 case MFW_BTIPS_FTPS_DISCONNECT_EVENT:
445 mfw_btips_signal(E_BTIPS_FTPS_DISCONNECT_EVENT,mmiInd);
446 break;
447
448 case MFW_BTIPS_FTPS_PUT_COMP_EVENT:
449 mfw_btips_signal(E_BTIPS_FTPS_PUT_COMP_EVENT,mmiInd);
450 break;
451
452 case MFW_BTIPS_FTPS_DELETE_COMP_EVENT:
453 mfw_btips_signal(E_BTIPS_FTPS_DELETE_COMP_EVENT,mmiInd);
454 break;
455
456 }
457 }
458
459 /*---------------------------------------------------------------------------
460 * GoepOpName
461 *---------------------------------------------------------------------------
462 *
463 * Synopsis: Return a pointer to the name of the current server operation.
464 *
465 * Return: ASCII String pointer.
466 *
467 */
468 static const char *GoepOpName(GoepOperation Op)
469 {
470 switch (Op) {
471 case GOEP_OPER_PUSH:
472 return "Push";
473 case GOEP_OPER_PULL:
474 return "Pull";
475 case GOEP_OPER_CONNECT:
476 return "Connect";
477 case GOEP_OPER_DISCONNECT:
478 return "Disconnect";
479 case GOEP_OPER_SETFOLDER:
480 return "Set Folder";
481 case GOEP_OPER_DELETE:
482 return "Delete";
483 case GOEP_OPER_ABORT:
484 return "Abort";
485 }
486 return "Unknown";
487 }
488
489 /*---------------------------------------------------------------------------
490 * General Purpose Debug functions
491 *---------------------------------------------------------------------------
492 */
493 const char *pBT_Status(I8 Status)
494 {
495 switch (Status) {
496 case BT_STATUS_SUCCESS:
497 return ("Success");
498 case BT_STATUS_FAILED:
499 return ("Failed");
500 case BT_STATUS_PENDING:
501 return ("Pending");
502 case BT_STATUS_BUSY:
503 return ("Busy");
504 case BT_STATUS_NO_RESOURCES:
505 return ("No Resources");
506 case BT_STATUS_NOT_FOUND:
507 return ("Not Found");
508 case BT_STATUS_DEVICE_NOT_FOUND:
509 return ("Device Not Found");
510 case BT_STATUS_CONNECTION_FAILED:
511 return ("Connection Failed");
512 case BT_STATUS_TIMEOUT:
513 return ("Timeout");
514 case BT_STATUS_NO_CONNECTION:
515 return ("No Connection");
516 case BT_STATUS_INVALID_PARM:
517 return ("Invalid parameter");
518 case BT_STATUS_IN_PROGRESS:
519 return ("In Progress");
520 case BT_STATUS_RESTRICTED:
521 return ("Restricted");
522 case BT_STATUS_INVALID_TYPE:
523 return ("Invalid Type");
524 case BT_STATUS_HCI_INIT_ERR:
525 return ("HCI Initialization Error");
526 case BT_STATUS_NOT_SUPPORTED:
527 return ("Not Supported");
528 case BT_STATUS_IN_USE:
529 return ("In Use");
530 case BT_STATUS_SDP_CONT_STATE:
531 return ("SDP Continue");
532 case BT_STATUS_CANCELLED:
533 return ("Cancelled");
534 }
535 return ("UNKNOWN");
536 }
537
538 #endif
539