📄 net_conn.c
字号:
*perr = NET_CONN_ERR_NONE;
}
/*$PAGE*/
/*
*********************************************************************************************************
* NetConn_ID_TransportGet()
*
* Description : Get a network connection's transport layer handle identifier.
*
* Argument(s) : conn_id Handle identifier of network connection to get transport layer handle identifier.
*
* perr Pointer to variable that will receive the return error code from this function :
*
* NET_CONN_ERR_NONE Network connection handle identifier get
* successful.
*
* ---- RETURNED BY NetConn_IsUsed() : ----
* NET_ERR_INIT_INCOMPLETE Network initialization NOT complete.
* NET_CONN_ERR_INVALID_CONN Invalid network connection number.
* NET_CONN_ERR_NOT_USED Network connection NOT currently used.
*
* Return(s) : Network connection's transport layer handle identifier, if NO errors.
*
* NET_CONN_ID_NONE, otherwise.
*
* Caller(s) : various.
*
* This function is an INTERNAL network protocol suite function & SHOULD NOT be called by
* application function(s).
*
* Note(s) : none.
*********************************************************************************************************
*/
NET_CONN_ID NetConn_ID_TransportGet (NET_CONN_ID conn_id,
NET_ERR *perr)
{
NET_CONN *pconn;
NET_CONN_ID conn_id_transport;
/* ---------------- VALIDATE NET CONN ----------------- */
if (conn_id == NET_CONN_ID_NONE) {
*perr = NET_CONN_ERR_NONE;
return (NET_CONN_ID_NONE);
}
#if (NET_ERR_CFG_ARG_CHK_DBG_EN == DEF_ENABLED) /* -------------- VALIDATE NET CONN USED -------------- */
(void)NetConn_IsUsed(conn_id, perr);
if (*perr != NET_CONN_ERR_NONE) {
return (NET_CONN_ID_NONE);
}
#endif
pconn = &NetConn_Tbl[conn_id];
conn_id_transport = pconn->ID_Transport; /* Get net conn's transport id. */
*perr = NET_CONN_ERR_NONE;
return (conn_id_transport);
}
/*$PAGE*/
/*
*********************************************************************************************************
* NetConn_ID_TransportSet()
*
* Description : Set a network connection's transport layer handle identifier.
*
* Argument(s) : conn_id Handle identifier of network connection to set transport layer handle
* identifier.
*
* conn_id_transport Connection's transport layer handle identifier.
*
* perr Pointer to variable that will receive the return error code from this function :
*
* NET_CONN_ERR_NONE Network connection's handle identifier
* successfully set.
*
* --- RETURNED BY NetConn_IsUsed() : ---
* NET_ERR_INIT_INCOMPLETE Network initialization NOT complete.
* NET_CONN_ERR_INVALID_CONN Invalid network connection number.
* NET_CONN_ERR_NOT_USED Network connection NOT currently used.
*
* Return(s) : none.
*
* Caller(s) : various.
*
* This function is an INTERNAL network protocol suite function & MUST NOT be called by
* application function(s).
*
* Note(s) : none.
*********************************************************************************************************
*/
void NetConn_ID_TransportSet (NET_CONN_ID conn_id,
NET_CONN_ID conn_id_transport,
NET_ERR *perr)
{
#if ((NET_CTR_CFG_ERR_EN == DEF_ENABLED) && \
(CPU_CFG_CRITICAL_METHOD == CPU_CRITICAL_METHOD_STATUS_LOCAL))
CPU_SR cpu_sr;
#endif
NET_CONN *pconn;
/* ---------------- VALIDATE NET CONN ----------------- */
if (conn_id == NET_CONN_ID_NONE) {
*perr = NET_CONN_ERR_NONE;
return;
}
#if (NET_ERR_CFG_ARG_CHK_DBG_EN == DEF_ENABLED) /* -------------- VALIDATE NET CONN USED -------------- */
(void)NetConn_IsUsed(conn_id, perr);
if (*perr != NET_CONN_ERR_NONE) {
return;
}
#endif
/* ------------ VALIDATE TRANSPORT CONN ID ------------ */
if (conn_id_transport < NET_CONN_ID_NONE) {
NET_CTR_ERR_INC(NetConn_ErrInvalidConnCtr);
*perr = NET_CONN_ERR_INVALID_CONN;
return;
}
pconn = &NetConn_Tbl[conn_id];
pconn->ID_Transport = conn_id_transport; /* Set net conn's transport id. */
*perr = NET_CONN_ERR_NONE;
}
/*$PAGE*/
/*
*********************************************************************************************************
* NetConn_AddrLocalGet()
*
* Description : Get a network connection's local address.
*
* Argument(s) : conn_id Handle identifier of network connection to get local address.
*
* paddr_local Pointer to variable that will receive the return local address (see Note #1),
* if NO errors.
*
* paddr_len Pointer to a variable to ... :
*
* (a) Pass the size of the address buffer pointed to by 'paddr_local'.
* (b) Return the actual local address length, if NO errors;
* Return 0, otherwise.
*
* See also Note #2.
*
* perr Pointer to variable that will receive the return error code from this function :
*
* NET_CONN_ERR_NONE Network connection address get successful.
* NET_CONN_ERR_NULL_PTR Argument 'paddr_local'/'paddr_len'
* passed a NULL pointer.
* NET_CONN_ERR_INVALID_ADDR_LEN Invalid network connection address length.
* NET_CONN_ERR_ADDR_NOT_USED Network connection address NOT in use.
*
* ----- RETURNED BY NetConn_IsUsed() : -----
* NET_ERR_INIT_INCOMPLETE Network initialization NOT complete.
* NET_CONN_ERR_INVALID_CONN Invalid network connection number.
* NET_CONN_ERR_NOT_USED Network connection NOT currently used.
*
* Return(s) : none.
*
* Caller(s) : NetSock_ConnHandlerStream(),
* NetSock_ConnHandlerAddrRemoteValidate(),
* NetSock_TxDataHandlerDatagram(),
* NetSock_FreeAddr(),
* NetTCP_TxConnPrepareSegAddrs().
*
* This function is an INTERNAL network protocol suite function & SHOULD NOT be called by
* application function(s).
*
* Note(s) : (1) Network connection addresses maintained in network-order.
*
* (2) (a) Since 'paddr_len' parameter is both an input & output parameter (see 'Argument(s) :
* paddr_len'), ...
*
* (1) its input value, prior to use, MUST be ...
* (A) saved, & ...
* (B) validated; ...
*
* (2) while its output value MUST be initially configured to return a default error
* value in case of any function exit due to error/fault conditions.
*
* (b) In the case that the 'paddr_len' parameter is passed a null pointer, ...
*
* (1) NO input value is saved, ...
* (2) NO input value is validated or used.
*********************************************************************************************************
*/
/*$PAGE*/
void NetConn_AddrLocalGet (NET_CONN_ID conn_id,
CPU_INT08U *paddr_local,
NET_CONN_ADDR_LEN *paddr_len,
NET_ERR *perr)
{
#if ((NET_ERR_CFG_ARG_CHK_DBG_EN == DEF_ENABLED) && \
(NET_CTR_CFG_ERR_EN == DEF_ENABLED) && \
(CPU_CFG_CRITICAL_METHOD == CPU_CRITICAL_METHOD_STATUS_LOCAL))
CPU_SR cpu_sr;
#endif
#if (NET_ERR_CFG_ARG_CHK_DBG_EN == DEF_ENABLED)
NET_CONN_ADDR_LEN addr_len;
#endif
NET_CONN *pconn;
/* ------------------ VALIDATE ADDR ------------------- */
#if (NET_ERR_CFG_ARG_CHK_DBG_EN == DEF_ENABLED)
if (paddr_len == (NET_CONN_ADDR_LEN *)0) { /* See Note #2b. */
NET_CTR_ERR_INC(NetConn_ErrNullPtrCtr);
*perr = NET_CONN_ERR_NULL_PTR;
return;
}
addr_len = *paddr_len; /* Save initial addr len (see Note #2a1A). */
#endif
*paddr_len = 0; /* Cfg dflt addr len for err (see Note #2a2). */
#if (NET_ERR_CFG_ARG_CHK_DBG_EN == DEF_ENABLED)
if (addr_len < NET_CONN_CFG_ADDR_LEN) { /* Validate initial addr len (see Note #2a1B). */
NET_CTR_ERR_INC(NetConn_ErrInvalidConnAddrLenCtr);
*perr = NET_CONN_ERR_INVALID_ADDR_LEN;
return;
}
if (paddr_local == (CPU_INT08U *)0) {
NET_CTR_ERR_INC(NetConn_ErrNullPtrCtr);
*perr = NET_CONN_ERR_NULL_PTR;
return;
}
/* -------------- VALIDATE NET CONN USED -------------- */
(void)NetConn_IsUsed(conn_id, perr);
if (*perr != NET_CONN_ERR_NONE) {
return;
}
#endif
pconn = &NetConn_Tbl[conn_id];
/* -------------- VALIDATE NET CONN ADDR -------------- */
if (pconn->AddrLocalValid != DEF_YES) { /* If net conn local addr NOT avail, rtn err. */
*perr = NET_CONN_ERR_ADDR_NOT_USED;
return;
}
Mem_Copy((void *) paddr_local, /* Copy & rtn net conn local addr. */
(void *)&pconn->AddrLocal[0],
(CPU_SIZE_T) NET_CONN_CFG_ADDR_LEN);
*paddr_len = NET_CONN_CFG_ADDR_LEN;
*perr = NET_CONN_ERR_NONE;
}
/*$PAGE*/
/*
*********************************************************************************************************
* NetConn_AddrLocalSet()
*
* Description : Set a network connection's local address.
*
* Argument(s) : conn_id Handle identifier of network connection to set local address.
*
* paddr_local Pointer to local address (see Note #1).
*
* addr_len Length of local address (in octets).
*
* addr_over_wr Allow local address overwrite :
*
* DEF_NO Do NOT overwrite local address.
* DEF_YES Overwrite local address.
*
* perr Pointer to variable that will receive the return error code from this function :
*
* NET_CONN_ERR_NONE Network connection address successfully set.
* NET_CONN_ERR_NULL_PTR Argument 'paddr_local' passed a NULL
* pointer.
* NET_CONN_ERR_INVALID_ADDR_LEN Invalid network connection address length.
*
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -