Beispiel #1
0
uint32_t PPPFSM_destroy
   (
      PPPFSM_CFG_PTR    fsm
            /* [IN/OUT] - State Machine */
   )
{ /* Body */

#if RTCSCFG_ENABLE_IP4

   uint32_t error = PPP_OK;

   PPP_mutex_lock(&fsm->MUTEX);
   if (fsm->STATE > PPP_STATE_CLOSED) {
      error = RTCSERR_PPP_FSM_ACTIVE;
   } else {
      fsm->STATE = PPP_STATE_INITIAL;
   } /* Endif */
   PPP_mutex_unlock(&fsm->MUTEX);
   if (!error) {
      PPP_mutex_destroy(&fsm->MUTEX);
   } /* Endif */
   return error;

#else   

    return RTCSERR_IP_IS_DISABLED;

#endif /* RTCSCFG_ENABLE_IP4  */   

} /* Endbody */
Beispiel #2
0
uint_32 PPP_shutdown
   (
      _ppp_handle  handle
       /* [IN] - the PPP state structure */
   )
{ /* Body */

#if RTCSCFG_ENABLE_IP4 
   
   PPP_CFG_PTR    ppp_ptr = handle;
   _rtcs_sem      sem;
   uint_32         error = RTCS_OK;
   /* wait time  in 0.1 Sec */
   uint_32        wait_time  = 50; 
   /* delay time in mS */ 
   uint_32        delay_time = 100; 

   PPP_lowerdown(ppp_ptr);
   ppp_ptr->STOP_RX = TRUE;    
   while(ppp_ptr->STOP_RX)  
   {  
      /* Waiting before Rx task  will be closed or kill it. */
      _time_delay(delay_time);
       wait_time--;
       if(!wait_time)
       {
          error = RTCSERR_TIMEOUT;
          RTCS_task_destroy(ppp_ptr->RX_TASKID);
          break;
       }
   }
   /* Kill Tx task */
   RTCS_sem_init(&sem);
   PPP_send_shutdown(ppp_ptr, &sem);
   RTCS_sem_wait(&sem);
   RTCS_sem_destroy(&sem);
   RTCS_msgpool_destroy(ppp_ptr->MSG_POOL);
   CCP_destroy(ppp_ptr);
   LCP_destroy(ppp_ptr);
   PPP_mutex_destroy(&ppp_ptr->MUTEX);
   PPP_memfree(handle);
   return(error);
#else

    return RTCSERR_IP_IS_DISABLED;    

#endif /* RTCSCFG_ENABLE_IP4 */   

} /* Endbody */
Beispiel #3
0
uint32_t PPP_release
   (
      _ppp_handle  handle
       /* [IN] - the PPP state structure */
   )
{ /* Body */

#if RTCSCFG_ENABLE_IP4 
    PPP_CFG_PTR    ppp_ptr = handle;
    _rtcs_sem      sem;
    uint32_t        error = RTCS_OK;
    /* wait time  in 0.1 Sec */
    uint32_t        wait_time  = 50; 
    /* delay time in mS */ 
    uint32_t        delay_time = 100; 

    if (ppp_ptr == NULL)
    {
        return(RTCS_OK);
    }

    error = RTCS_if_unbind(ppp_ptr->IF_HANDLE, IPCP_get_local_addr(ppp_ptr->IF_HANDLE));
    if (error != RTCS_OK)
    {
        return(error);
    }

    ppp_ptr->STOP_RX = TRUE;

    /* Waiting before Rx task  will be closed or kill it. */   
    while(ppp_ptr->STOP_RX)  
    {  
        _time_delay(delay_time);
        wait_time--;
        if(!wait_time)
        {
            error = RTCSERR_TIMEOUT;
            RTCS_task_destroy(ppp_ptr->RX_TASKID);
            break;
        }
    }

    error = PPP_close(ppp_ptr);
    if (error != PPP_OK)
    {
        return(error);
    }

    /* Kill Tx task */
    RTCS_sem_init(&sem);
    PPP_send_shutdown(ppp_ptr, &sem);
    RTCS_sem_wait(&sem);
    RTCS_sem_destroy(&sem);

    error = _iopcb_close(ppp_ptr->DEVICE);
    if (error != RTCS_OK)
    {
        return(error);
    }

    error = _iopcb_ppphdlc_release(ppp_ptr->DEVICE);
    if (error != RTCS_OK)
    {
        return(error);
    }
    ppp_ptr->DEVICE = NULL;
    
    error = RTCS_msgpool_destroy(ppp_ptr->MSG_POOL);
    if (error != MQX_OK)
    {
        return(error);
    }
    /*
    error = CCP_destroy(ppp_ptr);
    if (error != PPP_OK)
    {
        return(error);
    }
    */
    error = LCP_destroy(ppp_ptr);
    if (error != PPP_OK)
    {
        return(error);
    }
    
    PPP_mutex_destroy(&ppp_ptr->MUTEX);
    
    if (ppp_ptr->IOPCB_DEVICE)
    {
        fflush(ppp_ptr->IOPCB_DEVICE);
        error = fclose(ppp_ptr->IOPCB_DEVICE);
        if (error != RTCS_OK)
        {
            return(error);
        }
    }
    
    error = RTCS_if_remove(ppp_ptr->IF_HANDLE);
    if (error != RTCS_OK)
    {
        return(error);
    }
    
    PPP_memfree(handle);
    return(error);
#else

    return RTCSERR_IP_IS_DISABLED;

#endif /* RTCSCFG_ENABLE_IP4 */   

} /* Endbody */
Beispiel #4
0
uint_32 PPP_initialize
   (
      _iopcb_handle       device,
            /* [IN] - I/O stream to use */
      _ppp_handle _PTR_   handle
            /* [OUT] - the PPP state structure */
   )
{ /* Body */

#if RTCSCFG_ENABLE_IP4 

   PPP_CFG_PTR          ppp_ptr;
   uint_32              i, error;

   /* Allocate the state structure */
   ppp_ptr = PPP_memalloc(sizeof(PPP_CFG));
   if (!ppp_ptr) {
      return RTCSERR_PPP_ALLOC_FAILED;
   } /* Endif */

   /* Initialize it */
   PPP_memzero(ppp_ptr, sizeof(PPP_CFG));
   ppp_ptr->LINK_STATE = FALSE;
   ppp_ptr->DEVICE = device;
   for (i = 0; i < PPP_CALL_MAX; i++) {
      ppp_ptr->LCP_CALL[i].CALLBACK = NULL;
      ppp_ptr->LCP_CALL[i].PARAM    = NULL;
   } /* Endfor */
   ppp_ptr->PROT_CALLS = NULL;
   ppp_ptr->RECV_OPTIONS = &PPP_DEFAULT_OPTIONS;
   ppp_ptr->SEND_OPTIONS = &PPP_DEFAULT_OPTIONS;

   /* Initialize the lwsem */
   if (PPP_mutex_init(&ppp_ptr->MUTEX)) {
      return RTCSERR_PPP_INIT_MUTEX_FAILED;
   } /* Endif */

   /* Initialize LCP */
   error = LCP_init(ppp_ptr);
   if (error) {
      PPP_mutex_destroy(&ppp_ptr->MUTEX);
      return error;
   } /* Endif */

   /* Initialize CCP */
   error = CCP_init(ppp_ptr);
   if (error) {
      LCP_destroy(ppp_ptr);
      PPP_mutex_destroy(&ppp_ptr->MUTEX);
      return error;
   } /* Endif */
   CCP_open(ppp_ptr);

   /* Create a pool of message buffers */
   ppp_ptr->MSG_POOL = RTCS_msgpool_create(sizeof(PPP_MESSAGE),
      PPP_MESSAGE_INITCOUNT, PPP_MESSAGE_GROWTH, PPP_MESSAGE_LIMIT);
   if (ppp_ptr->MSG_POOL == MSGPOOL_NULL_POOL_ID) {
      CCP_destroy(ppp_ptr);
      LCP_destroy(ppp_ptr);
      PPP_mutex_destroy(&ppp_ptr->MUTEX);
      return RTCSERR_PPP_CREATE_PKT_POOL_FAILED;
   } /* Endif */

 
   /* Create the Tx Task */
   error = RTCS_task_create("PPP tx", _PPPTASK_priority,
      _PPPTASK_stacksize + 1000,
      PPP_tx_task, ppp_ptr);
   if (error) {
     RTCS_msgpool_destroy(ppp_ptr->MSG_POOL);
      CCP_destroy(ppp_ptr);
      LCP_destroy(ppp_ptr);
     PPP_mutex_destroy(&ppp_ptr->MUTEX);
      return error;
   } /* Endif */

   /* Create the Rx Task        */
   /* Set task ready for run    */
   ppp_ptr->STOP_RX = FALSE; 
   
   error = RTCS_task_create("PPP rx", _PPPTASK_priority,
      _PPPTASK_stacksize + 1000,
      PPP_rx_task, ppp_ptr);
   if (error) {
      RTCS_msgpool_destroy(ppp_ptr->MSG_POOL);
      CCP_destroy(ppp_ptr);
      LCP_destroy(ppp_ptr);
      PPP_mutex_destroy(&ppp_ptr->MUTEX);
      return error;
   } /* Endif */

   /* Return the handle */
   ppp_ptr->VALID = PPP_VALID;
   *handle = ppp_ptr;
   return PPP_OK;

#else

    return RTCSERR_IP_IS_DISABLED;    

#endif /* RTCSCFG_ENABLE_IP4 */

} /* Endbody */