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 */
RTCSPCB_PTR RTCSPCB_alloc_dup ( RTCSPCB_PTR orig_rtcs_pcb /* [IN] packet to duplicate */ ) { RTCSPCB_PTR rtcs_pcb; rtcs_pcb = RTCSPCB_alloc(); if (rtcs_pcb != NULL) { RTCS_sem_destroy(&rtcs_pcb->DUPCOUNT); _mem_copy((unsigned char *)orig_rtcs_pcb, (unsigned char *)rtcs_pcb, sizeof(RTCSPCB)); rtcs_pcb->PCB.PRIVATE = rtcs_pcb; rtcs_pcb->PCBPTR = &rtcs_pcb->PCB; if (orig_rtcs_pcb->PCBPTR == &orig_rtcs_pcb->PCB) { /* Packet originated on this host */ RTCSPCB_DATA(rtcs_pcb) = rtcs_pcb->HEADER_FRAG_BUFFER + (RTCSPCB_DATA(orig_rtcs_pcb) - orig_rtcs_pcb->HEADER_FRAG_BUFFER); if (rtcs_pcb->IP_SUM_PTR) { rtcs_pcb->IP_SUM_PTR = rtcs_pcb->HEADER_FRAG_BUFFER + (orig_rtcs_pcb->IP_SUM_PTR - orig_rtcs_pcb->HEADER_FRAG_BUFFER); } } else { _mem_copy(orig_rtcs_pcb->PCBPTR->FRAG, rtcs_pcb->PCB.FRAG, sizeof(PCB_FRAGMENT)*2); } rtcs_pcb->PCB_FREE = NULL; rtcs_pcb->PCB_ORIG = NULL; RTCS_sem_init(&rtcs_pcb->DUPCOUNT); RTCSPCB_depend(rtcs_pcb, orig_rtcs_pcb); /* can't fail because we allocated pcb */ rtcs_pcb->UDP_REQUEST = NULL; rtcs_pcb->FREE_FRAG_BITFIELD = 0; PCBLOG(("\nPCB: Alloc_dup: returning %p, duplicate of %p", rtcs_pcb, orig_rtcs_pcb)); } return rtcs_pcb; }
static int32_t RTCSPCB_construct ( void *block ) { RTCSPCB_PTR rtcs_pcb = block; rtcs_pcb->PCB.FREE = RTCSPCB_free_internal; rtcs_pcb->PCB.PRIVATE = rtcs_pcb; rtcs_pcb->DUPPTR = NULL; RTCS_sem_init(&rtcs_pcb->DUPCOUNT); rtcs_pcb->PCB_ORIG = NULL; rtcs_pcb->FREE_FRAG_BITFIELD = 0; rtcs_pcb->UDP_REQUEST = NULL; return RTCS_OK; }
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 */
/*FUNCTION*------------------------------------------------------------- * * Function Name : PPP_init_fail * Returned Value : none * Comments : * Do cleanup when initialization fails. * *END*-----------------------------------------------------------------*/ void PPP_init_fail(PPP_CFG_PTR ppp_ptr, int stage) { if (stage > 0) { fclose(ppp_ptr->IOPCB_DEVICE); _mem_free(ppp_ptr->DEVICE_NAME); ppp_ptr->DEVICE_NAME = NULL; } if (stage > 1) { _lwsem_destroy(&ppp_ptr->MUTEX); } if (stage > 2) { LCP_destroy(ppp_ptr); } if (stage > 3) { // CCP_close(ppp_ptr); // CCP_destroy(ppp_ptr); } if (stage > 5) { LWSEM_STRUCT sem; RTCS_sem_init(&sem); PPP_send_shutdown(ppp_ptr, &sem); RTCS_sem_wait(&sem); RTCS_sem_destroy(&sem); } /* Message pool must be destroyed after we send shutdown message to TX task */ if (stage > 4) { RTCS_msgpool_destroy(ppp_ptr->MSG_POOL); } if (stage > 6) { uint32_t wait_time = 50; uint32_t delay_time = 100; ppp_ptr->STOP_RX = TRUE; while(ppp_ptr->STOP_RX) { _time_delay(delay_time); wait_time--; if(!wait_time) { RTCS_task_destroy(ppp_ptr->RX_TASKID); break; } } } if (stage > 7) { _iopcb_close(ppp_ptr->DEVICE); } if (stage > 8) { RTCS_if_unbind(ppp_ptr->IF_HANDLE, IPCP_get_local_addr(ppp_ptr->IF_HANDLE)); RTCS_if_remove(ppp_ptr->IF_HANDLE); } _mem_free(ppp_ptr); }