/** * @param ucfolder */ BT_BOOL btmtk_ftpc_get_folder_content_ex(const U8 *ucFolderpath, const U8 *ucFilename) { bt_ftpc_pullfile_req_struct * req; if( NULL == act_client_cntx_p ) { return FALSE; } // copy it to folder_obj if ( BT_FTPC_STATE_CONNECTED== act_client_cntx_p->ftpc_state ) { if( NULL != ucFolderpath && NULL != ucFilename ) { btmtk_goep_compose_filepath( (const U8 *) ucFolderpath, (const U8 *) ucFilename, act_client_cntx_p->folder_obj , sizeof(act_client_cntx_p->folder_obj)/2 ); } BT_FTPC_STATE_TRANS(0, BT_FTPC_STATE_GETTING_FOLDER); /* send get current folder req */ /* construct get folder req ilm */ req = (bt_ftpc_pullfile_req_struct*) CONSTRUCT_LOCAL_PARAM(sizeof(bt_ftpc_pullfile_req_struct),TD_CTRL); GOEP_MEMSET( req, 0, sizeof(bt_ftpc_pullfile_req_struct)); req->goep_conn_id = ftpc_cntx_p->goep_conn_id[0]; ext_strncpy((S8 *) req->obj_mime_type, "x-obex/folder-listing", GOEP_MAX_MIME_TYPE); GOEP_MEMCPY( req->filepath, act_client_cntx_p->folder_obj, ext_ucs2strlen( (const S8 *)act_client_cntx_p->folder_obj) *2); req->filepath_len = ext_ucs2strlen( (const S8 *)act_client_cntx_p->folder_obj) *2; /* send get folder req */ bt_ftp_send_msg(MSG_ID_BT_FTPC_PULLFILE_REQ, req ,sizeof(bt_ftpc_pullfile_req_struct)); return TRUE; } return FALSE; }
/** * @brief FTP Client Deinit * FTP Client Disable */ BT_BOOL btmtk_ftpc_client_disable() { goep_disconnect_req_struct *req; /// disconnect all client and GOEP_TRACE((BT_FTP_TRC_CLASS, BT_FTPC_CNTX_DEINIT)); if(NULL == act_client_cntx_p || FALSE == ftpc_cntx_p->enable) { // has been disable return TRUE; } ftpc_cntx_p->enable = FALSE; switch (act_client_cntx_p->ftpc_state) { case BT_FTPC_STATE_IDLE: case BT_FTPC_STATE_DISCONNECTING: break; default: // construct disconnect req ilm req = (goep_disconnect_req_struct*) CONSTRUCT_LOCAL_PARAM(sizeof(goep_disconnect_req_struct), TD_CTRL); GOEP_MEMSET((U8 *)req, 0, sizeof(goep_disconnect_req_struct)); req->req_id = ftpc_cntx_p->req_id[0]; req->goep_conn_id = 0xFF; GOEP_MEMCPY(req->uuid, OBEX_FTP_UUID, 16); req->uuid_len = 16; // send disconnect req and connect cnf fail to CM bt_ftp_send_msg(MSG_ID_BT_FTPC_DISCONNECT_REQ, req, sizeof(goep_disconnect_req_struct)); BT_FTPC_STATE_TRANS(0, BT_FTPC_STATE_DISCONNECTING); break; } return TRUE; }
BT_BOOL btmtk_ftpc_get_status(bt_ftpc_status_struct *status){ if( NULL == status || status->u4Size != sizeof(bt_ftpc_status_struct) ){ return FALSE; } GOEP_MEMSET( (U8 *)status, 0, sizeof(bt_ftpc_status_struct) ); status->u4Size = sizeof(bt_ftpc_status_struct); if( act_client_cntx_p ){ status->ftpc_state = act_client_cntx_p->ftpc_state; GOEP_MEMCPY((U8 *)&status->bdaddr, (U8 *)&act_client_cntx_p->ftpc_bt_device, sizeof(act_client_cntx_p->ftpc_bt_device)); status->u4TotalSize = act_client_cntx_p->ftpc_total_len; // it could be zero and size is unknown status->u4DataSize = act_client_cntx_p->ftpc_data_len; // since remote could send unknow-size file GOEP_MEMCPY((U8 *)status->ftpc_filepath, (U8 *)act_client_cntx_p->push_local_path, sizeof(status->ftpc_filepath)-2); GOEP_MEMCPY((U8 *)status->ftpc_obj_name, (U8 *)act_client_cntx_p->ftpc_obj_name, sizeof(status->ftpc_obj_name) -2); status->challeng_options = act_client_cntx_p->challeng_options; GOEP_MEMCPY( (U8*)status->realm, (const U8 *)act_client_cntx_p->realm, sizeof(status->realm) ); } return TRUE; }
S32 btmtk_goep_fs_findnext(void *ptr , bt_ftp_obj_info_struct *ftp_file_info) { #ifdef BTMTK_GOEP_USE_WIN32_FS long *plong; U32 test_arrtibe; struct _wfinddata_t c_file; if( NULL == ptr || NULL == ftp_file_info) { return EXT_FS_ERR; } plong = ptr; GOEP_MEMSET( (U8 *) ftp_file_info, 0, sizeof(bt_ftp_obj_info_struct) ); if( 0 == _wfindnext( (long)*plong, &c_file ) ) { //ext_asc_str_n_to_ucs2_str( ftp_file_info->file_name, c_file.name, 260/2); ext_ucs2ncpy( (S8 *)ftp_file_info->file_name, (const S8 *)c_file.name, sizeof(ftp_file_info->file_name)/2 ); update_win32_file_time(ftp_file_info); // ok. find the next test_arrtibe = (_A_SUBDIR & c_file.attrib); ftp_file_info->file_size = c_file.size; if( _A_SUBDIR == test_arrtibe ) { ftp_file_info->isFile = FALSE; } else { ftp_file_info->isFile = TRUE; } return EXT_FS_OK; } #endif #ifdef BTMTK_ON_WISE FS_DOSDirEntry dir_entry; bt_ftp_find_struct *findstruct; U8 filename[ BTMTK_EP_MAX_FILENAME_LEN ]; U8 ucfilename[ BTMTK_EP_MAX_FILENAME_LEN ]; if( NULL != ptr ) { findstruct = (bt_ftp_find_struct *) ptr; if( 0 <= FS_FindNext( (FS_HANDLE) findstruct->hFile , &dir_entry, (U16 *) filename, sizeof(filename) ) ) { static_convert_DirEntry_to_file_info( &dir_entry, ftp_file_info , filename); memset( ucfilename, 0, sizeof( ucfilename) ); ext_chset_ucs2_to_utf8_string( (U8 *)ucfilename, sizeof(ucfilename) - 1, (U8 *)filename ); GOEP_Report("[ftp][fs] findnext file:(%s)", ucfilename); return EXT_FS_OK; } } #endif #ifdef BTMTK_ON_LINUX return static_linux_fill_file_info(ftp_file_info); #endif return EXT_FS_ERR; }
/** * @brief pull a file from remote ftp server * @param ucFilePath the send file's path and filename that will be using by btmtk_goep_open_rstream * @see btmtk_goep_open_rstream */ BT_BOOL btmtk_ftpc_pull_file_ex(const U8 *local_folderpath, const U8 *ucName, const U8 *ucNewName, U8 srm_enable, U8 waitCount) { bt_ftpc_pullfile_req_struct *req; if( NULL == act_client_cntx_p ) { return FALSE; } if( NULL == ucName && NULL == ucNewName ){ return FALSE; } if( NULL == ucName || NULL == ucNewName ){ /* one of them is NULL. Set two are the same */ ucName = (ucNewName!=NULL?ucNewName:ucName); ucNewName = ucName; } #ifdef __BT_GOEP_V2__ /// if connection type is 1 (l2cap), turn on srm mode if( act_client_cntx_p && (1 == act_client_cntx_p->ftpc_conntype) ){ srm_enable = TRUE; }else{ srm_enable = FALSE; } OS_Report("[AUTO] turn srm_enable to %d", srm_enable); #endif /// check state and push a push req switch (act_client_cntx_p->ftpc_state) { case BT_FTPC_STATE_CONNECTED: /* copy ucName to ftpc_obj_name */ memset( act_client_cntx_p->ftpc_filepath, 0, sizeof(act_client_cntx_p->ftpc_filepath)); bt_ftp_compose_path(local_folderpath, ucNewName, (U8 *) act_client_cntx_p->ftpc_filepath, sizeof(act_client_cntx_p->ftpc_filepath)/2); ext_ucs2ncpy( (S8 *) act_client_cntx_p->ftpc_obj_name, (const S8 *) ucName, sizeof(act_client_cntx_p->ftpc_obj_name) ); /* send get obj req */ req = (bt_ftpc_pullfile_req_struct*) CONSTRUCT_LOCAL_PARAM(sizeof(bt_ftpc_pullfile_req_struct),TD_CTRL); GOEP_MEMSET( req, 0, sizeof(bt_ftpc_pullfile_req_struct)); req->goep_conn_id = ftpc_cntx_p->goep_conn_id[0]; ext_ucs2ncpy((S8 *) req->obj_name, (S8 *) act_client_cntx_p->ftpc_obj_name, sizeof(req->obj_name)/2 ); bt_ftp_ucs2_htons( (U8 *)req->obj_name, (U8 *)req->obj_name ); ext_ucs2ncpy((S8 *) req->filepath, (S8 *)act_client_cntx_p->ftpc_filepath, sizeof(act_client_cntx_p->ftpc_filepath)/2); req->filepath_len = ext_ucs2strlen( (const S8 *)req->filepath)*2; req->srm_enable = srm_enable; req->srm_waitcount = waitCount; /* switch state */ BT_FTPC_STATE_TRANS(0, BT_FTPC_STATE_GETTING_OBJ); bt_ftp_send_msg(MSG_ID_BT_FTPC_PULLFILE_REQ, req,sizeof(bt_ftpc_pullfile_req_struct)); return TRUE; break; default: break; } return FALSE; }
/** * @brief This function is to go to the root folder. * FTP Client Change Folder (optional) * @return TRUE send request success. wait for BT_FTPCUI_SETPATHED event **/ BT_BOOL btmtk_ftpc_goto_root_folder(void) { // TODO check the state and /*----------------------------------------------------------------*/ /* Local Variables */ /*----------------------------------------------------------------*/ /*----------------------------------------------------------------*/ /* Code Body */ /*----------------------------------------------------------------*/ GOEP_TRACE ((BT_FTP_TRC_CLASS, BT_FTPC_ROOT_FOLDER, act_client_cntx_p->ftpc_state, ftpc_cntx_p->goep_conn_id[0])); if (NULL == act_client_cntx_p) { //TODO fault error return FALSE; } // Change MMI FTC state switch (act_client_cntx_p->ftpc_state) { case BT_FTPC_STATE_CONNECTED: { goep_set_folder_req_struct *req; BT_FTPC_STATE_TRANS(0, BT_FTPC_STATE_SETTING_ROOT_FOLDER); // construct set folder req ilm req = (goep_set_folder_req_struct*) CONSTRUCT_LOCAL_PARAM(sizeof(goep_set_folder_req_struct),TD_CTRL); GOEP_MEMSET( (U8 *)req, 0, sizeof(goep_set_folder_req_struct)); req->goep_conn_id = ftpc_cntx_p->goep_conn_id[0]; req->setpath_flag = GOEP_ROOT_FOLDER; GOEP_MEMCPY(req->uuid, OBEX_FTP_UUID, 16); req->uuid_len = 16; // send set folder req bt_ftp_send_msg(MSG_ID_BT_FTPC_SET_FOLDER_REQ, req ,sizeof(goep_set_folder_req_struct)); break; } default: /* Incorrect state */ // Incorrect state, callback and return error // It could be in pulling state. should not close the recv file handle GOEP_TRACE( (BT_FTP_TRC_CLASS, BT_FTPC_STATE_ERROR, act_client_cntx_p->ftpc_state)); return FALSE; } return TRUE; }
/** * @brief This is common function to abort connecting * Abort the connecting **/ BT_BOOL btmtk_ftpc_connect_cancel() { /*----------------------------------------------------------------*/ /* Local Variables */ /*----------------------------------------------------------------*/ goep_disconnect_req_struct *req; /*----------------------------------------------------------------*/ /* Code Body */ /*----------------------------------------------------------------*/ GOEP_TRACE( (BT_FTP_TRC_CLASS, BT_FTPC_CONNECT_CANCEL, act_client_cntx_p->ftpc_state) ); if( NULL == act_client_cntx_p ){ //TODO: fault error. log return FALSE; } switch(act_client_cntx_p->ftpc_state) { case BT_FTPC_STATE_IDLE: return FALSE; case BT_FTPC_STATE_GETTING_FOLDER: bt_ftpc_send_tpdisconnect_message(0); BT_FTPC_STATE_TRANS(0, BT_FTPC_STATE_TPDISCONNECTING); return TRUE; case BT_FTPC_STATE_CONNECTING: // construct disconnect req ilm req = (goep_disconnect_req_struct*) CONSTRUCT_LOCAL_PARAM(sizeof(goep_disconnect_req_struct),TD_CTRL); GOEP_MEMSET( (U8 *)req, 0, sizeof(goep_disconnect_req_struct)); req->req_id = ftpc_cntx_p->req_id[0]; req->goep_conn_id = 0xFF; GOEP_MEMCPY(req->uuid, OBEX_FTP_UUID, 16); req->uuid_len = 16; // send disconnect req and connect cnf fail to CM bt_ftp_send_msg(MSG_ID_BT_FTPC_DISCONNECT_REQ, req, sizeof(goep_disconnect_req_struct) ); BT_FTPC_STATE_TRANS(0, BT_FTPC_STATE_DISCONNECTING); return TRUE; default: break; } return FALSE; }
/** * @brief This function is to go to the parent folder. * FTP Client Change Folder (optional) * @return TRUE send request success. wait for BT_FTPCUI_SETPATHED event **/ BT_BOOL btmtk_ftpc_back_folder(void) { /*----------------------------------------------------------------*/ /* Local Variables */ /*----------------------------------------------------------------*/ /*----------------------------------------------------------------*/ /* Code Body */ /*----------------------------------------------------------------*/ GOEP_TRACE((BT_FTP_TRC_CLASS, BT_FTPC_BACK_FOLDER, act_client_cntx_p->ftpc_state, ftpc_cntx_p->goep_conn_id[0])); if (NULL == act_client_cntx_p) { return FALSE; } /* Change MMI FTPC state */ switch (act_client_cntx_p->ftpc_state) { case BT_FTPC_STATE_CONNECTED: { goep_set_folder_req_struct *req; BT_FTPC_STATE_TRANS(0, BT_FTPC_STATE_SETTING_BACK_FOLDER); /* construct set folder req ilm */ req = (goep_set_folder_req_struct*) CONSTRUCT_LOCAL_PARAM(sizeof(goep_set_folder_req_struct),TD_CTRL); GOEP_MEMSET( (U8 *)req, 0, sizeof(goep_set_folder_req_struct)); req->goep_conn_id = ftpc_cntx_p->goep_conn_id[0]; req->setpath_flag = GOEP_BACK_FOLDER; GOEP_MEMCPY(req->uuid, OBEX_FTP_UUID, 16); req->uuid_len = 16; /* send set folder req */ bt_ftp_send_msg(MSG_ID_BT_FTPC_SET_FOLDER_REQ, req ,sizeof(goep_set_folder_req_struct)); break; } default: /* Incorrect state */ /* Incorrect state, callback and return error */ GOEP_TRACE( (BT_FTP_TRC_CLASS, BT_FTPC_STATE_ERROR, act_client_cntx_p->ftpc_state)); return FALSE; } return TRUE; }
/** * @brief This function is to truncate object name if exceeds max buffer size * PARAMETERS * new_name [OUT] * old_name [IN] * max_len [IN] **/ void bt_goep_truncate_ntoh_filename(U16 *dst_name, const U16 *src_netname, U16 max_dst_len) { /*----------------------------------------------------------------*/ /* Local Variables */ /*----------------------------------------------------------------*/ U32 src_name_len; U16 *p_ext, *p1; U32 ext_len; U16 copy_len; S8 l_wave[8]; if( 0 == max_dst_len ){ GOEP_ASSERT(0); } /*----------------------------------------------------------------*/ /* Code Body */ /*----------------------------------------------------------------*/ src_name_len = ext_ucs2strlen((const S8*)src_netname); // max_dst_len /= ENCODING_LENGTH; max_dst_len /= 2; //TODO unicode is 2 byte if (src_name_len < max_dst_len) { /* need not truncate */ ext_ucs2ncpy((S8 *)dst_name, (S8 *) src_netname, max_dst_len); p1 = dst_name; for(; *p1; p1++) { *p1 = bt_goep_ntohs(*p1); } *p1 = (U16)'\0'; } else { /* need truncate */ GOEP_MEMSET( (U8*) dst_name, 0, max_dst_len * 2 ); //* ENCODING_LENGTH); /* find filename ext */ p_ext = (U16 *)ext_ucs2rchr((const S8 *)(S8 *)src_netname, (U16)(L'.')); if(p_ext) { ext_len = ext_ucs2strlen((const S8*)p_ext); } else { ext_len = 0; } /* 1 char for '~'; 1 char for \0 */ copy_len = (U16) (max_dst_len - ext_len - 1 - 1 ); ext_ucs2ncpy((S8 *) l_wave, (const S8*) L"-", 8); p1 = (U16 *)l_wave; for(; *p1; p1++) { *p1 = bt_goep_ntohs(*p1); } ext_ucs2ncpy((S8 *)dst_name, (const S8 *)src_netname, copy_len); ext_ucs2ncat((S8 *)dst_name, (const S8 *)l_wave, max_dst_len); if (p_ext) { ext_ucs2ncat((S8 *)dst_name, (const S8 *)p_ext, max_dst_len); } p1 = dst_name; for(; *p1; p1++) { *p1 = bt_goep_ntohs(*p1); } *p1 = (U16)'\0'; } }
/** * @brief This function is to browse a new folder or refresh the current folder * FTP Client Change Folder * Only could enter one level directory * @param name the sub folder to enter * @return TRUE send request success wait for changed BT_FTPCUI_SETPATHED event * @see BT_FTPCUI_EVNT_T **/ BT_BOOL btmtk_ftpc_enter_folder(const U16 * name) { /*----------------------------------------------------------------*/ /* Local Variables */ /*----------------------------------------------------------------*/ goep_set_folder_req_struct *req; /*----------------------------------------------------------------*/ /* Code Body */ /*----------------------------------------------------------------*/ GOEP_TRACE((BT_FTP_TRC_CLASS, BT_FTPC_CHANGE_FOLDER, act_client_cntx_p->ftpc_state, ftpc_cntx_p->goep_conn_id[0])); if (NULL == act_client_cntx_p) { //TODO fault error return FALSE; } // refresh current folder GOEP_TRACE((BT_FTP_TRC_CLASS, BT_FTPC_CHANGE_FOLDER_FORWARD)); switch (act_client_cntx_p->ftpc_state) { case BT_FTPC_STATE_CONNECTED: BT_FTPC_STATE_TRANS(0, BT_FTPC_STATE_SETTING_FOLDER); break; default: // Incorrect state, callback and return error GOEP_TRACE( (BT_FTP_TRC_CLASS, BT_FTPC_STATE_ERROR, act_client_cntx_p->ftpc_state)); return FALSE; } GOEP_Report("[FTPC] enter_folder setup copy obj_name"); GOEP_MEMSET((U8 *)act_client_cntx_p->ftpc_obj_name, 0, sizeof(act_client_cntx_p->ftpc_obj_name)); ext_ucs2ncpy((S8 *) act_client_cntx_p->ftpc_obj_name, (const S8 *) name, (sizeof(act_client_cntx_p->ftpc_obj_name)-2)/2); GOEP_TRACE_PATH(BT_FTP_TRC_CLASS, BT_FTPC_TARGET_FILENAME, act_client_cntx_p->ftpc_obj_name); GOEP_Report("[FTPC] enter_folder setup build a msg"); // send set folder req req = (goep_set_folder_req_struct*) CONSTRUCT_LOCAL_PARAM(sizeof(goep_set_folder_req_struct), TD_CTRL); GOEP_MEMSET((U8 *)req, 0, sizeof(goep_set_folder_req_struct)); req->goep_conn_id = ftpc_cntx_p->goep_conn_id[0]; GOEP_MEMCPY(req->uuid, OBEX_FTP_UUID, 16); req->uuid_len = 16; if (2 == ext_ucs2strlen((const S8 *) act_client_cntx_p->ftpc_obj_name) && 0 == ext_ucs2cmp((const U8 *) L"..", (const U8 *)act_client_cntx_p->ftpc_obj_name)) { req->setpath_flag = GOEP_BACK_FOLDER; } else { GOEP_Report("[FTPC] enter_folder setup msg's folder_name"); req->setpath_flag = GOEP_FORWARD_FOLDER; ext_ucs2ncpy((S8 *) req->folder_name, (S8 *) act_client_cntx_p->ftpc_obj_name, sizeof(req->folder_name)/2); } req->folder_name[sizeof(req->folder_name)-2] = req->folder_name[sizeof(req->folder_name)-1] = 0; bt_ftp_ucs2_htons((U8 *)req->folder_name, (U8 *)req->folder_name); bt_ftp_send_msg(MSG_ID_BT_FTPC_SET_FOLDER_REQ, req ,sizeof(goep_set_folder_req_struct)); return TRUE; }
/** * @brief This function is to get file object. * FTP Client Get File */ BT_BOOL btmtk_ftpc_get_file_obj(const U8 *local_path, const U8 *ucName, const U8 *ucNewName) { /*----------------------------------------------------------------*/ /* Local Variables */ /*----------------------------------------------------------------*/ //U32 i; goep_pull_req_struct *req; /*----------------------------------------------------------------*/ /* Code Body */ /*----------------------------------------------------------------*/ GOEP_TRACE((BT_FTP_TRC_CLASS, BT_FTPC_GET_FILE_OBJ, act_client_cntx_p->ftpc_state)); if (NULL == act_client_cntx_p) { //TODO fault error return FALSE; } if (NULL == local_path || FALSE == btmtk_goep_is_folder_exist((const U16 *) local_path)) { GOEP_Report("[ftpc] func:get_file_obj wrong foldpath parameter\n"); return FALSE; } if( NULL == ucName || 0 == ext_ucs2strlen( (const S8 *) ucName ) ){ GOEP_Report( "[ftpc] func:get_file_obj wrong filename parameter\n"); return FALSE; } // Init the statistics for received object length act_client_cntx_p->ftpc_total_len = 0; act_client_cntx_p->ftpc_reamin_len = 0; act_client_cntx_p->ftpc_data_len = 0; act_client_cntx_p->total_len_type = BT_FTPC_TOTAL_LEN_NO_FIRST_PKT; act_client_cntx_p->flag_abort_req_sent = FALSE; GOEP_Report("[FTPC] get_file_obj set default attribute = 0"); ext_ucs2ncpy((S8 *) act_client_cntx_p->push_local_path, (S8 *)local_path, sizeof(act_client_cntx_p->push_local_path)/2); if (NULL == ucNewName || 0 == ext_ucs2strlen((const S8 *) ucNewName)) { GOEP_Report("[FTPC] get_file_obj compose name"); bt_ftp_compose_path(local_path, ucName, (U8 *) act_client_cntx_p->ftpc_filepath, sizeof(act_client_cntx_p->ftpc_filepath)/2); } else { bt_ftp_compose_path(local_path, ucNewName, (U8 *) act_client_cntx_p->ftpc_filepath, sizeof(act_client_cntx_p->ftpc_filepath)/2); } GOEP_Report("[FTPC] get_file_obj set default attribute = 0"); ext_ucs2ncpy((S8 *) act_client_cntx_p->ftpc_obj_name, (S8 *) ucName, sizeof(act_client_cntx_p->ftpc_obj_name)); if (!ucName) { GOEP_Report("[ftpc][wrn] func:get_file_obj wrong param\n"); BT_FTP_ASSERT(0); return FALSE; } switch (act_client_cntx_p->ftpc_state) { case BT_FTPC_STATE_CONNECTED: BT_FTPC_STATE_TRANS(0, BT_FTPC_STATE_GETTING_OBJ); break; default: // Incorrect state, callback and return error GOEP_TRACE( (BT_FTP_TRC_CLASS, BT_FTPC_STATE_ERROR, act_client_cntx_p->ftpc_state)); return FALSE; } // send get obj req GOEP_Report("[FTPC] get_file_obj prepare msg"); req = (goep_pull_req_struct*) CONSTRUCT_LOCAL_PARAM(sizeof(goep_pull_req_struct),TD_CTRL); GOEP_MEMSET((U8 *)req, 0, sizeof(goep_pull_req_struct)); req->goep_conn_id = ftpc_cntx_p->goep_conn_id[0]; req->pkt_type = GOEP_FIRST_PKT; GOEP_MEMCPY(req->uuid, OBEX_FTP_UUID, 16); req->uuid_len = 16; ext_ucs2ncpy((S8 *) req->obj_name, (S8 *) act_client_cntx_p->ftpc_obj_name, sizeof(req->obj_name)/2 ); req->obj_name[sizeof(req->obj_name)-2] = req->obj_name[sizeof(req->obj_name)-1] = 0; bt_ftp_ucs2_htons((U8 *)req->obj_name, (U8 *)req->obj_name); bt_ftp_send_msg(MSG_ID_BT_FTPC_PULL_REQ, req,sizeof(goep_pull_req_struct)); return TRUE; }
BT_BOOL btmtk_ftpc_connect_server_ex(btbm_bd_addr_t bd_addr, U8 type){ /*----------------------------------------------------------------*/ /* Local Variables */ /*----------------------------------------------------------------*/ static U8 req_id =0; U32 i; /*----------------------------------------------------------------*/ /* Code Body */ /*----------------------------------------------------------------*/ GOEP_TRACE( (BT_FTP_TRC_CLASS, BT_FTPC_CONNECT_SERVER) ); if( NULL == act_client_cntx_p || FALSE == ftpc_cntx_p->enable ){ GOEP_Report("[ftpc][int] func:connect_server Not active !"); return FALSE; } // Reset root folder content flag if( NULL == act_client_cntx_p || act_client_cntx_p != &(ftpc_cntx_p->conn_cntx[0]) ){ GOEP_Report("[ftpc][int] func:connect_server Not active !"); return FALSE; } req_id++; for (i = 0; i < FTP_MAX_SERVER_SUPPORT; i++) { goep_connect_req_struct *req; // TOOD: UI notify the connting to remoet device'addr if ((act_client_cntx_p + i)->ftpc_state == BT_FTPC_STATE_IDLE) { // update context ftpc_cntx_p->req_id[i] = req_id; (act_client_cntx_p + i)->got_root = 0; (act_client_cntx_p + i)->ftpc_bt_device.lap = bd_addr.lap; (act_client_cntx_p + i)->ftpc_bt_device.uap = bd_addr.uap; (act_client_cntx_p + i)->ftpc_bt_device.nap = bd_addr.nap; (act_client_cntx_p + i)->challeng_options = 0; GOEP_MEMSET( (act_client_cntx_p + i)->realm, 0, sizeof((act_client_cntx_p + i)->realm) ); // connect server // film res pkt_type attibute //FTP_DEBUG(kal_print("FTPC CONNECT_SERVER TRY TO FILM ILM\n");) if (FALSE == ext_nbuffer_isInit(&act_client_cntx_p->ftpc_mempool)) { if (FALSE == ext_nbuffer_init(&act_client_cntx_p->ftpc_mempool, act_client_cntx_p->ftpc_obj_buff_size)) { /// fail to alloc nbuffer GOEP_Report( "[FTPS][WRN] btmtk_ftpc_connect_server ext_nbuffer_init fail"); } } req = (goep_connect_req_struct*) CONSTRUCT_LOCAL_PARAM(sizeof(goep_connect_req_struct),TD_CTRL); GOEP_MEMSET( (U8 *)req, 0, sizeof(goep_connect_req_struct)); req->bd_addr.lap = bd_addr.lap; req->bd_addr.uap = bd_addr.uap; req->bd_addr.nap = bd_addr.nap; req->buf_ptr = (act_client_cntx_p + i)->ftpc_obj_buff; req->buf_size = (U16) (act_client_cntx_p+ i)->ftpc_obj_buff_size; //FTPC_MEM_BUFF_SIZE; #ifdef __BT_GOEP_V2__ req->buf_size = (0xfff0); // 10M unit #endif req->req_id = req_id; req->tp_type = GOEP_TP_BT; req->tptype = type; /* rfcomm or l2cap or both */ GOEP_Report("[FTPC] req->tptype:%d", type); (act_client_cntx_p + i)->discon_from_cm = FALSE; GOEP_MEMCPY(req->uuid, OBEX_FTP_UUID, 16); req->uuid_len = 16; /* send connect req to server */ BT_FTPC_STATE_TRANS(i, BT_FTPC_STATE_CONNECTING); bt_ftp_send_msg(MSG_ID_BT_FTPC_CONNECT_REQ, req ,sizeof(goep_connect_req_struct)); return TRUE; } else { GOEP_Report( "[ftpc][int] func:connect_server wrong state:%d\n", act_client_cntx_p->ftpc_state ); } } return FALSE; }
void btmtk_deinit_ftp_client(void){ GOEP_Report("[FTPC] btmtk_deinit_ftp_client"); ftpc_cntx_p->enable = FALSE; act_client_cntx_p = NULL; GOEP_MEMSET( (U8 *) ftpc_cntx_p, 0, sizeof(ftpc_cntx_p)); }
/** * @brief This function is to initialize FTPC context * FTP Client Enable * **/ BT_BOOL btmtk_ftpc_client_enable(void) { /*----------------------------------------------------------------*/ /* Local Variables */ /*----------------------------------------------------------------*/ U32 i; /*----------------------------------------------------------------*/ /* Code Body */ /*----------------------------------------------------------------*/ GOEP_TRACE ((BT_FTP_TRC_CLASS, BT_FTPC_CNTX_INIT)); if (FALSE != ftpc_cntx_p->enable) { GOEP_TRACE( (BT_FTP_TRC_CLASS, BT_FTPC_CNTX_INIT_WRN) ); return TRUE; } // ftpc context init act_client_cntx_p = &(ftpc_cntx_p->conn_cntx[0]); ftpc_cntx_p->ftpc_flag = 0; ftpc_cntx_p->curr_idx = 0xFF; ftpc_cntx_p->enable = TRUE; for (i = 0; i < FTP_MAX_SERVER_SUPPORT; i++) { ftpc_cntx_p->goep_conn_id[i] = 0xFF; ftpc_cntx_p->req_id[i] = 0xFF; ftpc_cntx_p->g_conn_id[i] = 0xFF; (act_client_cntx_p + i)->got_root = 0; (act_client_cntx_p + i)->browse_depth = 0; (act_client_cntx_p + i)->ftpc_total_len = 0; (act_client_cntx_p + i)->ftpc_reamin_len = 0; (act_client_cntx_p + i)->entity_cnt_cur_folder = 0; (act_client_cntx_p + i)->xml_parser_p = NULL; (act_client_cntx_p + i)->fh_ftpc_recv = (FHANDLE) FHANDLE_INVALID_VALUE; (act_client_cntx_p + i)->ftpc_state = BT_FTPC_STATE_IDLE; (act_client_cntx_p + i)->ftpc_data_len = 0; (act_client_cntx_p + i)->total_len_type = BT_FTPC_TOTAL_LEN_NO_FIRST_PKT; (act_client_cntx_p + i)->fh_ftpc_push = FHANDLE_INVALID_VALUE; (act_client_cntx_p + i)->ftpc_push_remain = 0; (act_client_cntx_p + i)->ftpc_use_nbuffer = FALSE; FTPC_MAKE_FOLDER_OBJECT((act_client_cntx_p + i)->folder_obj, i); GOEP_MEMSET((U8 *) &((act_client_cntx_p + i)->ftpc_bt_device), 0, sizeof(goep_bd_addr_struct)); GOEP_MEMSET((U8 *) &(act_client_cntx_p + i)->ftpc_obj_name, 0, FMGR_MAX_PATH_LEN); GOEP_MEMSET((U8 *) &(act_client_cntx_p + i)->ftpc_filepath, 0, sizeof((act_client_cntx_p + i)->ftpc_filepath)); bt_ftpc_reset_abort_req_sent_flag(); // get the shared buffer for ftpc (act_client_cntx_p + i)->ftpc_obj_buff_size = FTPC_MEM_BUFF_SIZE; (act_client_cntx_p + i)->ftpc_obj_buff = (U8*) btmtk_ftpc_get_profile_shared_int_buffer((act_client_cntx_p + i)->ftpc_obj_buff_size); //BT_FTP_ASSERT((act_client_cntx_p + i)->ftpc_obj_buff); #ifdef __BT_GOEP_V2__ // no need buffer #else if (!((act_client_cntx_p + i)->ftpc_obj_buff)) { bt_ext_err("[BT][FTP] Failed to initialize the shared buffer for client."); ftpc_cntx_p->enable = FALSE; return FALSE; } #endif (act_client_cntx_p + i)->ftpc_peer_mru = 512; // spec min value of OBEX support size (act_client_cntx_p + i)->discon_from_cm = FALSE; } return TRUE; }
S32 btmtk_goep_fs_findfirst(U8 *ucFolderPath, bt_ftp_find_struct **findstruct, bt_ftp_obj_info_struct *ftp_file_info) { #ifdef BTMTK_GOEP_USE_WIN32_FS char sdir[256]; char filter[64]; U32 test_arrtibe; struct _wfinddata_t c_file; long hFile; bt_ftp_find_struct *pfind; GOEP_MEMSET((U8 *)ftp_file_info, 0, sizeof(bt_ftp_obj_info_struct) ); ext_ucs2_str_n_to_asc_str(sdir, ucFolderPath, sizeof(sdir)); // keep the previous folder path g_oldcwd[0] = 0; if ( NULL == _wgetcwd( (U16 *)g_oldcwd, sizeof(g_oldcwd)/2 ) ) { /// cannot keep the current folder GOEP_Report("[FS][ERR] fail to get cwd bufsize:(%d) err:%d!", sizeof(g_oldcwd)/2, GetLastError()); return EXT_FS_ERR; } printf( "[fs] getcwd is '%s'\n", g_oldcwd); printf( "[fs] fs findfirst '%s' \n", sdir ); _wchdir( (U16 *) ucFolderPath ); ext_strncpy (filter, "*.*", 64); hFile = _wfindfirst(L"*.*", &c_file); if( -1 == hFile ) { return EXT_FS_ERR; } else { //plong = (long * )malloc(sizeof(long)); pfind = (bt_ftp_find_struct *) malloc( sizeof(bt_ftp_find_struct) ); *findstruct = pfind; if( *findstruct == NULL ) { return EXT_FS_ERR; } ((bt_ftp_find_struct *)*findstruct)->hFile = hFile; ext_ucs2ncpy( (S8 *) ftp_file_info->file_name, (const S8 *) c_file.name, sizeof(ftp_file_info->file_name)/2); update_win32_file_time(ftp_file_info); test_arrtibe = (_A_SUBDIR & c_file.attrib); if( _A_SUBDIR == test_arrtibe) { ftp_file_info->isFile = FALSE; } else { ftp_file_info->isFile = TRUE; } return EXT_FS_OK; } #endif #ifdef BTMTK_ON_WISE U8 *filter; S32 hFile; S32 len; bt_ftp_find_struct *pfind; FS_DOSDirEntry dir_entry; U8 filename[ BTMTK_EP_MAX_FILENAME_LEN ]; /// output //ext_ucs2ncpy (filter, (const U8 *)L"\\*.*", sizeof(filter)/2); len = ext_ucs2strlen((const S8*)ucFolderPath)*2 + 10; filter = (U8 *) get_ctrl_buffer( len ); // plus L"\\*.*" if( NULL == filter ) { return EXT_FS_ERR; } btmtk_os_memset( filter, 0, len); ext_ucs2ncpy( (U8 *) filter, (const U8 *) ucFolderPath , len-2); ext_ucs2ncat( (U8 *) filter, (const U8 *) L"\\*.*", len-2); ext_ucs2ncpy((S8 *)filename, (const U8 *)L"", (sizeof(filename)/2)-1); hFile = (S32) FS_FindFirst( (const WCHAR*)filter, 0, 0, &dir_entry, (U16*) filename, sizeof(filename) ); if( NULL == filter ) { free_ctrl_buffer(filter); filter = NULL; } if ( hFile >= 0) { GOEP_MEMSET((U8 *)ftp_file_info, 0, sizeof(bt_ftp_obj_info_struct) ); pfind = (bt_ftp_find_struct *) get_ctrl_buffer( sizeof(bt_ftp_find_struct) ); *findstruct = pfind; if( *findstruct == NULL ) { FS_FindClose( (FS_HANDLE) hFile ); return EXT_FS_ERR; } ((bt_ftp_find_struct *)*findstruct)->hFile = hFile; static_convert_DirEntry_to_file_info( &dir_entry, ftp_file_info , filename); return EXT_FS_OK; } else { return EXT_FS_ERR; } #endif #ifdef BTMTK_ON_LINUX int ret; int err_num; bt_ext_log("[GOEP_FS] btmtk_goep_fs_findfirst(): Linux Version."); ext_chset_ucs2_to_utf8_string((U8 *) g_folder_path, sizeof(g_folder_path)-1, ucFolderPath); // strncpy(g_folder_path, ucFolderPath, sizeof(g_folder_path)); bt_ext_log("[GOEP_FS] g_folder_path: %s", g_folder_path); g_opened_dir = opendir( g_folder_path); if (g_opened_dir == NULL) { err_num = errno; bt_ext_err("[FS_ERR] opendir() failed. %s", (char*) strerror(err_num)); return EXT_FS_ERR; } return static_linux_fill_file_info(ftp_file_info); #endif return EXT_FS_ERR; }