示例#1
0
文件: sh_ppp.c 项目: zhouglu/K60F120M
/*FUNCTION*------------------------------------------------
*
* Function Name: shell_ppp_stop
* Comments     : Shell command "ppp stop" is calling this function to stop PPP connection.
*
*END*-----------------------------------------------------*/
int_32 shell_ppp_stop(SHELL_PPP_LINK_PTR local_ppp)
{
    uint_32           error;

   /* Check if PPP is alive. */
    if(!local_ppp->PPP_HANDLE)
    {
      printf("Can not stop PPP.It is not started\n");
    }
   /* Cleanup PPP connection. */

   /* Unbind interface. */
    error = RTCS_if_unbind(local_ppp->PPP_IF_HANDLE, IPCP_get_local_addr(local_ppp->PPP_IF_HANDLE));
    if(default_ppp.PPP_HANDLE)
    {
       /* Send connection terminate request to remote server and close PPP connection. */
        error = PPP_close(local_ppp->PPP_HANDLE);

       /* Clean up all PPP structure. */
        error = PPP_shutdown(local_ppp->PPP_HANDLE);
        local_ppp->PPP_HANDLE =NULL;
    }
   /* Destroing the semafor. */
    error = _lwsem_destroy(&local_ppp->PPP_SEM);
    if(local_ppp->PPP_IF_HANDLE)
    {
       /* Unregister PPP interface. */
        error = RTCS_if_remove(local_ppp->PPP_IF_HANDLE);
        local_ppp->PPP_IF_HANDLE=0;
    }
    if(local_ppp->PPP_IO_DRIVER_HANDLE)
    {
       /* Closing PPP driver. */
        error = _iopcb_close(local_ppp->PPP_IO_DRIVER_HANDLE);
    }
    if(local_ppp->PPP_DEV_HANDLE)
    {
        /* Close PPP driver. */
         error = fclose(default_ppp.PPP_DEV_HANDLE);
    }
    if(local_ppp->PPP_CON_DEV_HANDLE)
    {
       /* Close Close PPP_DEVICE. */
        error = fclose(default_ppp.PPP_CON_DEV_HANDLE);
    }
    local_ppp->PPP_HANDLE = NULL;
   /* We need remove route. */
    RTCS_gate_remove(local_ppp->PPP_GATE_ADDR, INADDR_ANY, INADDR_ANY);
    if(error)
    {
      printf("\nSome error happend during closing PPP connection.\n");
      return RTCS_ERROR;
    }
    else
    {
      printf("PPP connection closed\n");
      return RTCS_OK;
    }
}
示例#2
0
static void PAP_close
   (
      pointer        handle,
            /* [IN] - the PPP state structure */
      PCB_PTR        pcb,
            /* [IN] - expired packet */
      boolean        hard
            /* [IN] - TRUE if this is a hard timeout (TO- event) */
   )
{ /* Body */

   PPP_close(handle);

} /* Endbody */
示例#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 */