📄 net_conn.c
字号:
* NET_CONN_ERR_NOT_USED Network connection NOT currently used.
*
* Return(s) : DEF_OK, if NO errors.
*
* DEF_FAIL, otherwise.
*
* Caller(s) : various.
*
* Note(s) : (1) #### Return value may NOT be necessary (remove before product release if unnecessary).
*********************************************************************************************************
*/
CPU_BOOLEAN NetConn_ID_AppCloneSet (NET_CONN_ID conn_id,
NET_CONN_ID conn_id_app,
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
#if (NET_ERR_CFG_ARG_CHK_DBG_EN == DEF_ENABLED)
CPU_BOOLEAN used;
#endif
NET_CONN *pconn;
/* ---------------- VALIDATE NET CONN ----------------- */
if (conn_id == NET_CONN_ID_NONE) {
*perr = NET_CONN_ERR_NONE;
return (DEF_FAIL);
}
#if (NET_ERR_CFG_ARG_CHK_DBG_EN == DEF_ENABLED)
if (conn_id < NET_CONN_ID_MIN) {
NET_CTR_ERR_INC(NetConn_ErrInvalidConnCtr);
*perr = NET_CONN_ERR_INVALID_CONN;
return (DEF_FAIL);
}
if (conn_id > NET_CONN_ID_MAX) {
NET_CTR_ERR_INC(NetConn_ErrInvalidConnCtr);
*perr = NET_CONN_ERR_INVALID_CONN;
return (DEF_FAIL);
}
#endif
pconn = &NetConn_Tbl[conn_id];
#if (NET_ERR_CFG_ARG_CHK_DBG_EN == DEF_ENABLED)
/* -------------- VALIDATE NET CONN USED -------------- */
used = DEF_BIT_IS_SET(pconn->Flags, NET_CONN_FLAG_USED);
if (used != DEF_YES) { /* If net conn NOT used, rtn err. */
NET_CTR_ERR_INC(NetConn_ErrNotUsedCtr);
*perr = NET_CONN_ERR_NOT_USED;
return (DEF_FAIL);
}
#endif
/* --------------- VALIDATE APP CONN ID --------------- */
if (conn_id_app < NET_CONN_ID_NONE) {
NET_CTR_ERR_INC(NetConn_ErrInvalidConnCtr);
*perr = NET_CONN_ERR_INVALID_CONN;
return (DEF_FAIL);
}
pconn->ID_AppClone = conn_id_app; /* Set net conn's app clone id. */
*perr = NET_CONN_ERR_NONE;
return (DEF_OK);
}
/*$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.
* NET_CONN_ERR_INVALID_CONN Invalid 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.
*
* Note(s) : (1) #### 'perr' may NOT be necessary (remove before product release if unnecessary).
*********************************************************************************************************
*/
NET_CONN_ID NetConn_ID_TransportGet (NET_CONN_ID conn_id,
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)
CPU_BOOLEAN used;
#endif
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)
if (conn_id < NET_CONN_ID_MIN) {
NET_CTR_ERR_INC(NetConn_ErrInvalidConnCtr);
*perr = NET_CONN_ERR_INVALID_CONN;
return (NET_CONN_ID_NONE);
}
if (conn_id > NET_CONN_ID_MAX) {
NET_CTR_ERR_INC(NetConn_ErrInvalidConnCtr);
*perr = NET_CONN_ERR_INVALID_CONN;
return (NET_CONN_ID_NONE);
}
#endif
pconn = &NetConn_Tbl[conn_id];
#if (NET_ERR_CFG_ARG_CHK_DBG_EN == DEF_ENABLED)
/* -------------- VALIDATE NET CONN USED -------------- */
used = DEF_BIT_IS_SET(pconn->Flags, NET_CONN_FLAG_USED);
if (used != DEF_YES) { /* If net conn NOT used, rtn err. */
NET_CTR_ERR_INC(NetConn_ErrNotUsedCtr);
*perr = NET_CONN_ERR_NOT_USED;
return (NET_CONN_ID_NONE);
}
#endif
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.
* NET_CONN_ERR_INVALID_CONN Invalid connection number.
* NET_CONN_ERR_NOT_USED Network connection NOT currently used.
*
* Return(s) : DEF_OK, if NO errors.
*
* DEF_FAIL, otherwise.
*
* Caller(s) : various.
*
* Note(s) : (1) #### Return value may NOT be necessary (remove before product release if unnecessary).
*********************************************************************************************************
*/
CPU_BOOLEAN 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
#if (NET_ERR_CFG_ARG_CHK_DBG_EN == DEF_ENABLED)
CPU_BOOLEAN used;
#endif
NET_CONN *pconn;
/* ---------------- VALIDATE NET CONN ----------------- */
if (conn_id == NET_CONN_ID_NONE) {
*perr = NET_CONN_ERR_NONE;
return (DEF_FAIL);
}
#if (NET_ERR_CFG_ARG_CHK_DBG_EN == DEF_ENABLED)
if (conn_id < NET_CONN_ID_MIN) {
NET_CTR_ERR_INC(NetConn_ErrInvalidConnCtr);
*perr = NET_CONN_ERR_INVALID_CONN;
return (DEF_FAIL);
}
if (conn_id > NET_CONN_ID_MAX) {
NET_CTR_ERR_INC(NetConn_ErrInvalidConnCtr);
*perr = NET_CONN_ERR_INVALID_CONN;
return (DEF_FAIL);
}
#endif
pconn = &NetConn_Tbl[conn_id];
#if (NET_ERR_CFG_ARG_CHK_DBG_EN == DEF_ENABLED)
/* -------------- VALIDATE NET CONN USED -------------- */
used = DEF_BIT_IS_SET(pconn->Flags, NET_CONN_FLAG_USED);
if (used != DEF_YES) { /* If net conn NOT used, rtn err. */
NET_CTR_ERR_INC(NetConn_ErrNotUsedCtr);
*perr = NET_CONN_ERR_NOT_USED;
return (DEF_FAIL);
}
#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 (DEF_FAIL);
}
pconn->ID_Transport = conn_id_transport; /* Set net conn's transport id. */
*perr = NET_CONN_ERR_NONE;
return (DEF_OK);
}
/*$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_NOT_USED Network connection NOT currently used.
* NET_CONN_ERR_INVALID_CONN Invalid connection number.
* NET_CONN_ERR_INVALID_ADDR_LEN Invalid connection address length.
* NET_CONN_ERR_ADDR_NOT_USED Network connection address NOT in use.
*
* Return(s) : DEF_OK, if NO errors.
*
* DEF_FAIL, otherwise.
*
* Caller(s) : NetSock_TxDataHandler(),
* NetSock_FreeAddr().
*
* 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 MUST be saved & validated prior to use, ...
* (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.
*
* (3) #### Return value may NOT be necessary (remove before product release if unnecessary).
*********************************************************************************************************
*/
/*$PAGE*/
CPU_BOOLEAN NetConn_AddrLocalGet (NET_CONN_ID conn_id,
CPU_INT08U
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -