6.4. Gateway
The gateway translates packets between PAN and LAN. It is generally associated with the PAN coordinator, that is, the PAN coordinator and the gateway are on the same physical node. Gateway functionality has to be enabled using the compile-time flags GW_ENA and PAN_COORD.
6.4.1. Functions
- void GW_rcvdMsgHndlr(UINT16_t msgType, UINT8_t bdHndl)
Handles messages received from either the PAN or LAN. Where required, function allocates memory and generates responses. Typically, sensor data is transparently passed across. When messages are to be relayed from LAN to a particular node, this function simply sets SYS_globalEvtMsk1 with SYS_GLOBAL_EVT_GW_RELAY_REQUEST and lets the main system loop of the PAN coordinator take care of triggering the actual transmission.
Parameters: - msgType – Message type
- bdHndl – Handle to memory containing the message. This is not relevant for messages that don’t have any payload. For messages relayed by the gateway transparently, memory handle is simply copied.
- void GW_init(void)
Initializes the gateway. A gateway may support multiple ways of communicating to the LAN: UART, Wi-Fi, GSM. This function configures interfaces that are supported. Function is typically called when the system boots up.
- void GW_relayCnfrm(UINT8_t moduleId, UINT8_t sts)
Send a confirmation back to the node that message was successfully relayed to the LAN. For example, the message could be sensor data. Function is called when main system loop sees that SYS_globalEvtMsk0 is set with SYS_GLOBAL_EVT_MAC_DATA_CONFIRM.
Parameters: - moduleId – Identity of the module requesting that this confirmation be sent.
- sts – Status of the message.
- void GW_relayMsgFromRemoteNode(UINT16_t srcShortAddr, MCPS_dataIndParams_s *dataIndParams_p)
Message from a remote node is relayed to LAN from this function.
Parameters: - shortAddr – Short address of the node from which message has originated.
- dataIndParams_p – Pointer to parameters controlling this message relay.
- void GW_sendNodeRegEvt(NM_nodeListEntry_s *nodeInfo_p)
When a node registers to the PAN coordinator, this event is indicated to the LAN. For example, such an event when received on the LAN may be used to update the user interface or database records. This function sends all details of the newly registered node.
Parameters: - nodeInfo_p – Points to details of the node just registered to the PAN coordinator.
- void GW_sendSysBootEvt(void)
When the gateway has completed booting up, this event is sent to the LAN. This event is a useful indication in case gateway reboots for some reason.
- void GW_sendLocalRtDiscStartedEvt(UINT16_t shortAddr)
Sometimes when LAN requests messages to be sent to a particular node, route may not be known. This function starts the route discovery procedure.
Parameters: - shortAddr – Short address of the node for which route discovery has been started.
- void GW_relayMsgToRemoteNode(void)
Messages sent by the LAN to particular nodes are simply relayed by the gateway using this function. Function is called when main system loop sees that SYS_globalEvtMsk1 is set with SYS_GLOBAL_EVT_GW_RELAY_REQUEST.
6.4.2. Globals
- GW_cntxt_s GW_cntxt
This is used only when the node is a gateway, when compilation flag GW_ENA is defined. This variable is used to pass the gateway context to other modules that need to access memory handles and associated parameters. UART interface is one such module that uses this variable.
6.4.3. Macros
#define LPWMN_GW_MSG_TYPE_NODE_CNT_REQ 0x1
#define LPWMN_GW_MSG_TYPE_NODE_LIST_REQ 0x3
#define LPWMN_GW_MSG_TYPE_RELAY_TO_NODE 0x5
#define LPWMN_GW_MSG_TYPE_RELAY_FROM_NODE 0x6
#define LPWMN_GW_MSG_TYPE_KEEP_ALIVE_REQ 0x7
#define LPWMN_GW_MSG_TYPE_KEEP_ALIVE_RESP 0x8
#define LPWMN_GW_MSG_TYPE_PING_NODE_REQ 0x9
#define LPWMN_GW_MSG_TYPE_NODE_PING_RESP 0xa
#define LPWMN_GW_MSG_TYPE_NODE_RT_DISC_STS 0x10
#define LPWMN_GW_MSG_TYPE_PATH_DISC_REQ 0x13
#define LPWMN_GW_MSG_TYPE_PATH_DISC_RESP 0x14
#define LPWMN_GW_MSG_TYPE_NODE_TRAFFIC_STATS_REQ 0x18
#define LPWMN_GW_MSG_TYPE_RESET_NODE_TRAFFIC_STATS 0x1a
#define LPWMN_GW_MSG_TYPE_STOP_TRAFFIC_REQ 0x1e
#define LPWMN_GW_MSG_TYPE_START_TRAFFIC_REQ 0x1f
#define LPWMN_GW_MSG_TYPE_GET_COORD_STATS 0x20
#define LPWMN_GW_MSG_TYPE_RESET_COORD_STATS 0x21
#define LPWMN_GW_MSG_TYPE_STOP_NWK 0x30
#define LPWMN_GW_MSG_TYPE_START_NWK 0x31
#define LPWMN_GW_MSG_TYPE_DISABLE_NODE_REG 0x40
#define LPWMN_GW_MSG_TYPE_ENABLE_NODE_REG 0x41
#define LPWMN_GW_MSG_TYPE_SET_NWK_PAN_ID 0x50
#define LPWMN_GW_MSG_TYPE_SET_NWK_CHANNEL 0x51
#define LPWMN_GW_MSG_TYPE_SET_PAN_COORD_EXT_ADDR 0x52
#define LPWMN_GW_MSG_TYPE_SET_RADIO_TX_PWR 0x53
#define LPWMN_GW_MSG_TYPE_GET_NWK_PAN_ID 0x59
#define LPWMN_GW_MSG_TYPE_GET_NWK_CHANNEL 0x5a
#define LPWMN_GW_MSG_TYPE_GET_PAN_COORD_EXT_ADDR 0x5b
#define LPWMN_GW_MSG_TYPE_GET_RADIO_TX_PWR 0x5c
#define LPWMN_GW_MSG_TYPE_SET_WCT 0x70 // set wall clock time
#define LPWMN_GW_MSG_TYPE_GET_WCT 0x71 // get wall clock time
#define LPWMN_MSG_TYPE_GET_UP_TIME 0x80 // in seconds
#define LPWMN_GW_MSG_TYPE_COORD_LOG 0x90
#define LPWMN_GW_MSG_TYPE_ENABLE_COORD_LOG 0x91
#define LPWMN_GW_MSG_TYPE_DISABLE_COORD_LOG 0x92
#define LPWMN_GW_MSG_TYPE_DEREG_NODE 0xa0
#define LPWMN_GW_MSG_TYPE_EVENT 0xb0
// Events sent to host by the PAN coordinator
#define LPWMN_GW_EVT_TYPE_NODE_REG 0x1
#define LPWMN_GW_EVT_TYPE_LOCAL_RT_DISC_STARTED 0x2
#define LPWMN_GW_EVT_TYPE_SYS_BOOT 0x3
#define LPWMN_GW_EVT_ID_LEN 0x1
#define LPWMN_GW_NODE_CNT_RESP_PYLD_LEN 2
#define LPWMN_GW_MSG_NODE_IDX_FIELD_LEN 2
#define LPWMN_GW_STS_SUCCESS 0x0
#define LPWMN_GW_STS_INV_REQ 0x1
#define LPWMN_GW_STS_INV_PARAMS 0x2
#define LPWMN_GW_STS_PREV_REQ_IN_PROGRESS 0x3
#define LPWMN_GW_STS_NWK_STOPPED 0x4
#define LPWMN_GW_STS_NO_ROUTE_TO_NODE 0x5
#define LPWMN_GW_STS_INV_PYLD_LEN 0x6
#define LPWMN_GW_STS_INV_RADIO_TX_PWR_SET_POINT 0x7