📄 tcp_ip.c
字号:
{ ui32 msg; Ni * attn; /*-------------------------------------------------------------------*/ /* Process chained NI attention requests. */ /*-------------------------------------------------------------------*/ if (NiAttnHead) { isrMask(); attn = NiAttnHead; NiAttnHead = NiAttnHead->entry; isrUnmask(); attn->poll(); } /*-------------------------------------------------------------------*/ /* Process TCP/IP timer ticks. */ /*-------------------------------------------------------------------*/ if (TmrCount) { isrMask(); --TmrCount; isrUnmask(); NetTimerTick(); } /*-------------------------------------------------------------------*/ /* If not empty, read from message queue. */ /*-------------------------------------------------------------------*/ if (QueCount) { /*-----------------------------------------------------------------*/ /* Decrement queue count. */ /*-----------------------------------------------------------------*/ isrMask(); --QueCount; isrUnmask(); /*-----------------------------------------------------------------*/ /* Advance pointer to next entry in queue message ring. */ /*-----------------------------------------------------------------*/ if (QueGet == &MsgQue[MSG_QUE_SIZE - 1]) QueGet = &MsgQue[0]; else ++QueGet; /*-----------------------------------------------------------------*/ /* Read message from event queue. */ /*-----------------------------------------------------------------*/ MsgPtr = QueGet->ptr; msg = QueGet->msg; /*-----------------------------------------------------------------*/ /* Process input protocol messages. */ /*-----------------------------------------------------------------*/ if (msg == DATA_IND) { RxBuf = MsgPtr; switch (RxBuf->type) { case ARP_TYPE: ArpIn(); break; case IP_TYPE: IpIn(); break; case RARP_TYPE: RarpIn(); break; } /*---------------------------------------------------------------*/ /* Free buffer unless reserved for application use. */ /*---------------------------------------------------------------*/ if (RxBuf) tcpRetBuf(&RxBuf); } /*-----------------------------------------------------------------*/ /* Else check for function callback request. */ /*-----------------------------------------------------------------*/ else if (msg == ATTN_REQ) QueGet->func(MsgPtr); /*-----------------------------------------------------------------*/ /* Else must be FREE_BUF message. */ /*-----------------------------------------------------------------*/ else { TcpAssert(msg == FREE_BUF); tcpRetBuf(&MsgPtr); } }}/***********************************************************************//* tcpPollReq: Pass NI ISR poll request to TCP/IP daemon *//* *//* Input: ni = pointer to network interface structure *//* *//***********************************************************************/void tcpPollReq(Ni *ni){ /*-------------------------------------------------------------------*/ /* Add to end of NI poll list. */ /*-------------------------------------------------------------------*/ ni->entry = NULL; isrMask(); if (NiAttnHead == NULL) NiAttnHead = ni; else NiAttnTail->entry = ni; NiAttnTail = ni; isrUnmask(); /*-------------------------------------------------------------------*/ /* If the TCP/IP daemon is blocked, make it ready. */ /*-------------------------------------------------------------------*/ if (DaemonBlocked) { DaemonBlocked = FALSE; taskWake(Daemon); }}/***********************************************************************//* TcpTryOut: Request output state machine to transmit *//* *//* Input: sock = pointer to socket control block *//* *//***********************************************************************/void TcpTryOut(SOCKET sock){ /*-------------------------------------------------------------------*/ /* If message post succeeds, reserve hold on socket. */ /*-------------------------------------------------------------------*/ if (NetPostMsg(TcpOut, sock, ATTN_REQ) == 0) ++sock->reserve_cnt; /*-------------------------------------------------------------------*/ /* Else atleast make sure its retransmit timer is running. */ /*-------------------------------------------------------------------*/ else if (sock->out_tmr.running == FALSE) NetTimerStart(&sock->out_tmr, sock->retrans_timeo);}/***********************************************************************//* tcpDataInd: Network interface data announcement *//* *//* Input: buf = pointer to buffer containing received data *//* *//***********************************************************************/void tcpDataInd(NetBuf *buf){ /*-------------------------------------------------------------------*/ /* If message post fails, free the receive buffer. */ /*-------------------------------------------------------------------*/ if (NetPostMsg(NULL, buf, DATA_IND)) tcpRetBuf(&buf);}/***********************************************************************//* NetPostMsg: Post message to TCP/IP processing queue *//* *//* Inputs: func = pointer to callback function *//* ptr = pointer to callback parameter *//* msg = coded message *//* *//* Returns: 0 if no error, else -1 if queue full *//* *//***********************************************************************/int NetPostMsg(void (*func)(void *ptr), void *ptr, ui32 msg){ /*-------------------------------------------------------------------*/ /* Mask interrupts because critical section follows. */ /*-------------------------------------------------------------------*/ isrMask(); /*-------------------------------------------------------------------*/ /* If queue full, update statistics and return -1. */ /*-------------------------------------------------------------------*/ if (QueCount == MSG_QUE_SIZE) { ++Net.PutFailed; isrUnmask(); return -1; } /*-------------------------------------------------------------------*/ /* Update queue message count and high water mark too. */ /*-------------------------------------------------------------------*/ if (++QueCount > Net.QHighWater) Net.QHighWater = QueCount; /*-------------------------------------------------------------------*/ /* Advance pointer to next position in queue message ring. */ /*-------------------------------------------------------------------*/ if (QuePut == &MsgQue[MSG_QUE_SIZE - 1]) QuePut = &MsgQue[0]; else ++QuePut; /*-------------------------------------------------------------------*/ /* Write message to queue. */ /*-------------------------------------------------------------------*/ QuePut->func = func; QuePut->ptr = ptr; QuePut->msg = msg; /*-------------------------------------------------------------------*/ /* Unmask interrupts. */ /*-------------------------------------------------------------------*/ isrUnmask(); /*-------------------------------------------------------------------*/ /* If the TCP/IP daemon is blocked, make it ready. */ /*-------------------------------------------------------------------*/ if (DaemonBlocked) { DaemonBlocked = FALSE; taskWake(Daemon); } return 0;}/***********************************************************************//* NiBufFree: Delete any queued buffers associated with interface *//* *//* Input: ni = pointer to interface structure being deleted *//* *//***********************************************************************/void NiBufFree(Ni *ni){ int i; NetBuf *buf; NetMsg *qp = QueGet; /*-------------------------------------------------------------------*/ /* Check all messages in queue. */ /*-------------------------------------------------------------------*/ for (i = 0; i < QueCount; ++i) { /*-----------------------------------------------------------------*/ /* Advance pointer to next entry in queue message ring. */ /*-----------------------------------------------------------------*/ if (qp == &MsgQue[MSG_QUE_SIZE - 1]) qp = &MsgQue[0]; else ++qp; /*-----------------------------------------------------------------*/ /* Look for DATA_IND messages and IpOut callbacks. */ /*-----------------------------------------------------------------*/ if ((qp->msg == DATA_IND) || (qp->func == IpOut)) { /*---------------------------------------------------------------*/ /* Change to FREE_BUF message if associated with specified NI. */ /*---------------------------------------------------------------*/ buf = qp->ptr; if (buf->ni == ni) qp->msg = FREE_BUF; } }}/***********************************************************************//* tcpPerror: Print TCP/IP error message on stdout *//* *//* Input: err_code = error code to convert to error message *//* *//***********************************************************************/void tcpPerror(int err_code){ int i; /*-------------------------------------------------------------------*/ /* Look in error message table for a match. */ /*-------------------------------------------------------------------*/ for (i = 0; err_entry[i].err_code; ++i) if (err_entry[i].err_code == err_code) break; /*-------------------------------------------------------------------*/ /* Print error message. */ /*-------------------------------------------------------------------*/ printf("%s\n\r", err_entry[i].err_msg);}/***********************************************************************//* SockRelease: Decrement number of socket reservations and free *//* socket control block if none remain *//* *//* Input: sock = pointer to socket control block *//* */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -