?? net_icmp.c
字號:
default:
NetICMP_TxPktDiscard(pmsg_err, perr);
return; /* Prevent 'break NOT reachable' compiler warning. */
}
*perr = NET_ICMP_ERR_NONE;
}
/*$PAGE*/
/*
*********************************************************************************************************
* NetICMP_TxMsgReq()
*
* Description : (1) Transmit ICMP Request Message :
*
* (a) Validate ICMP Request Message :
*
* (1) Validate the following arguments :
*
* (A) Type
* (B) Code
*
* (2) Validation of the following arguments deferred to NetIP_Tx() :
*
* (A) Type of Service (TOS) See RFC #1349, Section 5.1
* (B) Time-to-Live (TTL)
* (C) Destination Address
* (D) IP flags
* (E) IP options
*
* (3) Validation ignores the following arguments :
*
* (A) Data
* (B) Data length
*
* (b) Get buffer for ICMP Request Message :
*
* (1) Calculate ICMP Request Message buffer size
* (2) Copy data into ICMP Request Message
* (3) Initialize ICMP Request Message buffer controls
*
* (c) Prepare ICMP Request Message :
*
* (1) Type See Note #1cA
* (2) Code See Note #1cA
* (3) Identification (ID)
* (4) Sequence Number
* (5) Data
* (6) Timestamps
*
* (A) See 'net_icmp.h ICMP MESSAGE TYPES & CODES Notes #2 & #3' for supported ICMP
* message types & codes.
*
* (B) Timestamp Request Message
*
* (1) "The Originate Timestamp is the time the sender last touched the message
* before sending it" (RFC #792, Section 'Timestamp or Timestamp Reply Message :
* Description').
*
* (d) Transmit ICMP Request Message
*
* (e) Free ICMP Request Message buffer
*
* (f) Update transmit statistics
*
* (g) Return ICMP Request Message Identification & Sequence Number
* OR
* NULL id & sequence number structure, on failure
*
*
*$PAGE*
* Argument(s) : type ICMP Request Message type (see Note #1cA) :
*
* NET_ICMP_MSG_TYPE_ECHO_REQ
* NET_ICMP_MSG_TYPE_TS_REQ
* NET_ICMP_MSG_TYPE_ADDR_MASK_REQ
*
* code ICMP Request Message code (see Note #1cA).
*
* id ICMP Request Message id (see 'net_os.c NetOS_ICMP_TxMsgReq() Note #3b').
*
* TOS Specific TOS to transmit IP packet
* (see 'net_ip.h IP HEADER TYPE OF SERVICE (TOS) DEFINES').
*
* TTL Specific TTL to transmit IP packet (see 'net_ip.h IP HEADER DEFINES').
*
* addr_dest Destination IP address.
*
* flags Flags to select transmit options; bit-field flags logically OR'd :
*
* NET_IP_FLAG_NONE No transmit flags selected.
* NET_IP_FLAG_TX_DONT_FRAG Set IP 'Don't Frag' flag.
*
* popts Pointer to one or more IP options configuration data structures :
*
* NULL NO IP transmit options configuration.
* NET_IP_OPT_CFG_ROUTE_TS Route &/or Internet Timestamp options configuration.
* NET_IP_OPT_CFG_SECURITY Security options configuration
* (see 'net_ip.h Note #1f').
*
* perr Pointer to variable that will receive the return error code from this function :
*
* NET_ICMP_ERR_NONE ICMP Request Message successfully transmitted.
* NET_ERR_INIT_INCOMPLETE Network initialization NOT complete.
*
* ---- RETURNED BY NetICMP_TxPktDiscard() : ----
* NET_ERR_TX Transmit error; packet discarded.
*
* Return(s) : ICMP Request Message's Identification (ID) & Sequence Numbers, if NO errors.
*
* NULL Identification (ID) & Sequence Numbers, otherwise.
*
* Caller(s) : NetOS_ICMP_TxMsgReq().
*
* This function is an INTERNAL network protocol suite function & SHOULD NOT be called by
* application function(s).
*
* Note(s) : (2) NetICMP_TxMsgReq() blocked until network initialization completes; perform NO action.
*
* (3) NetICMP_TxMsgReq() is the internal ICMP handler for ICMP Request Messages. Its
* global declaration is required since NetOS_ICMP_TxMsgReq() calls the handler function
* from the OS port file (see also 'net_os.c NetOS_ICMP_TxMsgReq() Note #1').
*
* (4) Default case already invalidated in NetICMP_TxMsgReqValidate(). However, the default
* case is included as an extra precaution in case 'type' is incorrectly modified.
*
* (5) Assumes network buffer's protocol header size is large enough to accomodate ICMP header
* size (see 'net_buf.h NETWORK BUFFER INDEX & SIZE DEFINES Note #1').
*
* (6) Some buffer controls were previously initialized in NetBuf_Get() when the buffer
* was allocated earlier in this function. These buffer controls do NOT need to be
* re-initialized but are shown for completeness.
*
* (7) (a) ICMP message Check-Sum MUST be calculated AFTER the entire ICMP message has been
* prepared. In addition, ALL multi-octet words are converted from host-order to
* network-order since "the sum of 16-bit integers can be computed in either byte
* order" [RFC #1071, Section 2.(B)].
*
* (b) ICMP message Check-Sum field MUST be cleared to '0' BEFORE the ICMP message
* Check-Sum is calculated (see RFC #792, Sections 'Echo or Echo Reply Message :
* Checksum', 'Timestamp or Timestamp Reply Message : Checksum'; & RFC #950,
* Appendix I 'Address Mask ICMP', Section 'ICMP Fields : Checksum').
*
* (c) The ICMP message Check-Sum field is returned in network-order & MUST NOT be re-
* converted back to host-order (see 'net_util.c NetUtil_16BitOnesCplChkSumHdrCalc()
* Note #3b' & 'net_util.c NetUtil_16BitOnesCplChkSumDataCalc() Note #4b').
*
* (8) Network buffer already freed by lower layer; only increment error counter.
*********************************************************************************************************
*/
/*$PAGE*/
NET_ICMP_REQ_ID_SEQ NetICMP_TxMsgReq (CPU_INT08U type,
CPU_INT08U code,
CPU_INT16U id,
NET_IP_TOS TOS,
NET_IP_TTL TTL,
NET_IP_ADDR addr_dest,
CPU_INT16U flags,
void *popts,
void *p_data,
CPU_INT16U data_len,
NET_ERR *perr)
{
#if (CPU_CFG_CRITICAL_METHOD == CPU_CRITICAL_METHOD_STATUS_LOCAL)
CPU_SR cpu_sr;
#endif
NET_ICMP_REQ_ID_SEQ id_seq;
CPU_INT16U msg_size_hdr;
CPU_INT16U msg_size_data;
CPU_INT16U msg_size_tot;
CPU_INT16U msg_seq_nbr;
CPU_INT16U msg_ix;
CPU_INT16U msg_ix_data;
CPU_INT16U msg_chk_sum;
NET_TS ts;
NET_BUF *pmsg_req;
NET_BUF_HDR *pmsg_req_hdr;
NET_ICMP_HDR_ECHO *picmp_hdr_echo;
NET_ICMP_HDR_TS *picmp_hdr_ts;
NET_ICMP_HDR_ADDR_MASK *picmp_hdr_addr;
NET_ERR err;
/* Prepare err rtn val. */
id_seq.ID = 0;
id_seq.SeqNbr = 0;
#if (NET_ERR_CFG_ARG_CHK_EXT_EN == DEF_ENABLED)
if (Net_InitDone != DEF_YES) { /* If init NOT complete, exit tx (see Note #2). */
*perr = NET_ERR_INIT_INCOMPLETE;
return (id_seq);
}
#endif
/* ------------- VALIDATE ICMP TX REQ MSG ------------- */
NetICMP_TxMsgReqValidate(type, code, &err);
if (err != NET_ICMP_ERR_NONE) {
NetICMP_TxPktDiscard((NET_BUF *)0, perr);
return (id_seq);
}
/*$PAGE*/
/* --------------- GET ICMP REQ MSG BUF --------------- */
/* Calc req msg buf size. */
switch (type) {
case NET_ICMP_MSG_TYPE_ECHO_REQ:
msg_size_hdr = NET_ICMP_HDR_SIZE_ECHO;
if (p_data != (void *)0) {
msg_size_data = data_len;
} else {
msg_size_data = 0;
}
break;
case NET_ICMP_MSG_TYPE_TS_REQ:
#if 1 /* ???? Rtn err OR ignore data? */
if (p_data != (void *)0) {
NetICMP_TxPktDiscard((NET_BUF *)0, perr);
return (id_seq);
}
if (data_len > 0) {
NetICMP_TxPktDiscard((NET_BUF *)0, perr);
return (id_seq);
}
#endif
msg_size_hdr = NET_ICMP_HDR_SIZE_TS;
msg_size_data = 0;
break;
case NET_ICMP_MSG_TYPE_ADDR_MASK_REQ:
#if 1 /* ???? Rtn err OR ignore data? */
if (p_data != (void *)0) {
NetICMP_TxPktDiscard((NET_BUF *)0, perr);
return (id_seq);
}
if (data_len > 0) {
NetICMP_TxPktDiscard((NET_BUF *)0, perr);
return (id_seq);
}
#endif
msg_size_hdr = NET_ICMP_HDR_SIZE_ADDR_MASK;
msg_size_data = 0;
break;
default: /* See Note #4. */
NetICMP_TxPktDiscard((NET_BUF *)0, perr);
return (id_seq); /* Prevent 'break NOT reachable' compiler warning. */
}
msg_size_tot = msg_size_hdr + msg_size_data;
#if (NET_ERR_CFG_ARG_CHK_DBG_EN == DEF_ENABLED)
if (NET_BUF_DATA_TX_IX < msg_size_hdr) { /* See Note #5. */
NetICMP_TxPktDiscard((NET_BUF *)0, perr);
NET_CTR_ERR_INC(NetICMP_ErrTxInvalidBufIxCtr);
return (id_seq);
}
#endif
msg_ix = NET_BUF_DATA_TX_IX - msg_size_hdr;
pmsg_req = NetBuf_Get((NET_BUF_SIZE) msg_size_tot, /* Get req msg buf. */
(NET_BUF_SIZE) msg_ix,
(CPU_INT16U ) NET_BUF_FLAG_NONE,
(NET_ERR *)&err);
if (err != NET_BUF_ERR_NONE) {
NetICMP_TxPktDiscard(pmsg_req, perr);
return (id_seq);
}
/*$PAGE*/
/* Init req msg buf ctrls. */
pmsg_req_hdr = &pmsg_req->Hdr;
pmsg_req_hdr->ICMP_MsgIx = (CPU_INT16U )msg_ix;
pmsg_req_hdr->ICMP_MsgLen = (CPU_INT16U )msg_size_tot;
pmsg_req_hdr->ICMP_HdrLen = (CPU_INT16U )msg_size_hdr;
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -