Problems with the bearer


#1

i have this Code

/***************************************************************************/
/*  File       : ftp.c                                                 */
/*-------------------------------------------------------------------------*/
/*  Object     : Manage the ftp connection                                */
/*                                                                         */
/*  Contents   :                                                           */
/*                                                                         */
/***************************************************************************/
#include "adl_global.h"
#include "common.h"
#include "constants.h"
#include "ftp.h"
#include "wip.h"


static wip_channel_t ftpChannel=NULL;
static wip_channel_t dataChannel=NULL;

#define GPRS_APN      "xxx"
#define GPRS_USER     ""
#define GPRS_PASSWORD ""
#define GPRS_PINCODE  "0000"
#define DST_SERVER    "xxx.xxx.xxx.xxx"     /* Address the FTP server */
#define DST_USER      "xxx"       /* My FTP username */
#define DST_PASSWORD  "xxx" /* My FTP password */
#define DST_FILENAME  "newdata.txt"        /* Name of the file to put */
#define DST_ISPASSIVE FALSE             /* Active or passive mode? */

/***************************************************************************/
// Function called to handle sim events. When sim is full init we can set the
// apn server
FUNC void simHandler(u8 Event) 
{ 
   bool rsp;
   switch ( Event ) 
   { 
      case ADL_SIM_EVENT_PIN_OK : 
         {   TRACE (( TRACE_LEVEL_FTP, "ADL_SIM_EVENT_PIN_OK" ));} 
      break; 
      case ADL_SIM_EVENT_REMOVED : 
         {TRACE (( TRACE_LEVEL_FTP, "ADL_SIM_EVENT_REMOVED" ));} 
      break; 
      case ADL_SIM_EVENT_INSERTED : 
         {TRACE (( TRACE_LEVEL_FTP, "ADL_SIM_EVENT_INSERTED" ));} 
      break; 
      case ADL_SIM_EVENT_FULL_INIT : 
         {TRACE (( TRACE_LEVEL_FTP, "ADL_SIM_EVENT_FULL_INIT" ));
          rsp=createBearer();     
          if (rsp==TRUE){
          TRACE (( TRACE_LEVEL_FTP, "GPRS OK" ));
          adl_atSendResponse(ADL_AT_RSP,"\r\nBearer OK \r\n");
          }
          else {
          adl_atSendResponse(ADL_AT_RSP,"\r\nBearer ERROR \r\n");
          TRACE (( TRACE_LEVEL_FTP, "GPRS NOT OK" ));
          }
         } 
      break; 
      case ADL_SIM_EVENT_PIN_ERROR : 
         {TRACE (( TRACE_LEVEL_FTP, "ADL_SIM_EVENT_PIN_ERROR" ));} 
      break; 
      case ADL_SIM_EVENT_PIN_NO_ATTEMPT : 
         {TRACE (( TRACE_LEVEL_FTP, "ADL_SIM_EVENT_PIN_NO_ATTEMPT" ));} 
      break; 
      case ADL_SIM_EVENT_PIN_WAIT : 
         {TRACE (( TRACE_LEVEL_FTP, "ADL_SIM_EVENT_PIN_WAIT" ));} 
      break; 
      default : 
         {   TRACE (( TRACE_LEVEL_FTP, "other PIN event" ));} 
      break; 
   } 

}

static void dataHandler(wip_event_t *event,void *context){
    switch (event->kind) {
		case WIP_CEV_WRITE:{
      TRACE((TRACE_LEVEL_FTP,"WIP_CEV_WRITE "));
			wip_write(dataChannel,"this is a test",14);
            wip_close( dataChannel);   dataChannel   = NULL;
            wip_close( ftpChannel); ftpChannel = NULL;
        }
            break;    
		default:adl_atSendResponse(ADL_AT_RSP,"\r\n Tried to write\r\n");
			break;
	}
}

static void ftpHandler(wip_event_t *event,void *context){
    if (event->kind==WIP_CEV_OPEN){
            // ftp connection just established
      TRACE((TRACE_LEVEL_FTP,"ftp connection just established "));
      dataChannel=wip_putFile(ftpChannel,"test.txt",dataHandler,NULL);
    }
    else {	
		 TRACE ((TRACE_LEVEL_FTP,"some other ftp event"));
         adl_atSendResponse(ADL_AT_RSP,"\r\n some other ftp event\r\n");
    }
}

static void gprsBearerHandler(wip_bearer_t br,s8 event,void *context){
    switch (event) {
		case WIP_BEV_IP_CONNECTED:{
      TRACE((TRACE_LEVEL_FTP,"WIP_BEV_IP_CONNECTED "));
       wip_debug( "Opening FTP connection...\n");
         ftpChannel=wip_FTPCreateOpts (
    DST_SERVER,  ftpHandler, NULL,
    WIP_COPT_USER,     DST_USER,
    WIP_COPT_PASSWORD, DST_PASSWORD,
    WIP_COPT_PASSIVE,  DST_ISPASSIVE,
    WIP_COPT_END);
        }	
			break;
        case WIP_BEV_IP_DISCONNECTED:{
          TRACE((TRACE_LEVEL_FTP,"WIP_BEV_IP_DISCONNECTED "));
        }
            break;    
		default:{
            TRACE ((TRACE_LEVEL_FTP,"Some problems with the bearer"));             
        }
			break;
	}
}

bool createBearer( ){
  wip_bearer_t gprsBearer;
    if (wip_bearerOpen(&gprsBearer,"GPRS",gprsBearerHandler,NULL)!=0 ){
        // cannot open the bearer
        TRACE((TRACE_LEVEL_FTP,"cannot open the bearer"));
        return FALSE;
    }
    //configure the gprs connection
    if (wip_bearerSetOpts(&gprsBearer,WIP_BOPT_GPRS_APN,GPRS_APN,WIP_BOPT_LOGIN,GPRS_USER,WIP_BOPT_PASSWORD,GPRS_PASSWORD,WIP_BOPT_END)!=0){
    //cannot configure the bearer
   TRACE((TRACE_LEVEL_FTP,"cannot configure the bearer"));
    wip_bearerClose(&gprsBearer);
    return FALSE;
    }
    // start connection
    if (wip_bearerStart(&gprsBearer)!=0){
    //cannot start the bearer
    TRACE((TRACE_LEVEL_FTP,"cannot start the bearer"));
    wip_bearerClose(&gprsBearer);
    return FALSE;
    }
    return TRUE;
}
/***************************************************************************/
/*  Function   : cfg_gprs                                                  */
/*-------------------------------------------------------------------------*/
/*  Object     : initialize GPRS connection, then launch entry_point() on  */
/*               success.                                                  */
/*                                                                         */
/*-------------------------------------------------------------------------*/
/*  Variable Name     |IN |OUT|GLB|  Utilisation                           */
/*--------------------+---+---+---+----------------------------------------*/
/*  entry_point       | X |   |   |Function run after successful connection*/
/*--------------------+---+---+---+----------------------------------------*/
/***************************************************************************/
void putDataToFtp () {
    adl_simState_e simState;
    bool rsp;
    int r;
    /* Initialize the stack */
      r = wip_netInitOpts( 
      WIP_NET_OPT_DEBUG_PORT, WIP_NET_DEBUG_PORT_UART1,
      WIP_NET_OPT_END); 
    if (r!=0){
    TRACE((TRACE_LEVEL_FTP,"Error with netinit"));
        return FALSE;
    }       
    simState=adl_simGetState();
    if (simState==ADL_SIM_STATE_PIN_WAIT){
       TRACE (( TRACE_LEVEL_FTP, "Entering pin" ));
       adl_simSubscribe((adl_simHdlr_f)simHandler, parameters[PARAM_PIN]);
   }
   else {
       adl_atSendResponse(ADL_AT_RSP,"\r\n Pin ok creating bearer \r\n");
       rsp=createBearer();
   }
}

When the sim full init event occurs and the createbearere function is called when wip_bearerOpen i get an acces violation error what is wrong with this code i can’t figure it out. I am trying to put a file on a ftp.


#2

sorry i figured it out

wip_bearerSetOpts(&gprsBearer[b]

that & was the problem[/b]