1 /** @file router_transport.c
4 * Copyright (C) Cambridge Silicon Radio Ltd 2006-2010. All rights reserved.
6 * Refer to LICENSE.txt included with this source code for details on
9 ****************************************************************************/
11 #include "unifi_priv.h"
13 #include "csr_sched.h"
14 #include "csr_msgconv.h"
16 #include "sme_userspace.h"
18 #include "csr_wifi_hostio_prim.h"
19 #include "csr_wifi_router_lib.h"
20 #include "csr_wifi_router_sef.h"
21 #include "csr_wifi_router_converter_init.h"
22 #include "csr_wifi_router_ctrl_lib.h"
23 #include "csr_wifi_router_ctrl_sef.h"
24 #include "csr_wifi_router_ctrl_converter_init.h"
25 #include "csr_wifi_sme_prim.h"
26 #include "csr_wifi_sme_sef.h"
27 #include "csr_wifi_sme_converter_init.h"
28 #ifdef CSR_SUPPORT_WEXT
29 #ifdef CSR_SUPPORT_WEXT_AP
30 #include "csr_wifi_nme_ap_prim.h"
31 #include "csr_wifi_nme_ap_sef.h"
32 #include "csr_wifi_nme_ap_converter_init.h"
36 static unifi_priv_t *drvpriv = NULL;
37 void CsrWifiRouterTransportInit(unifi_priv_t *priv)
39 unifi_trace(priv, UDBG1, "CsrWifiRouterTransportInit: \n");
42 (void)CsrMsgConvInit();
43 CsrWifiRouterConverterInit();
44 CsrWifiRouterCtrlConverterInit();
45 CsrWifiSmeConverterInit();
46 #ifdef CSR_SUPPORT_WEXT
47 #ifdef CSR_SUPPORT_WEXT_AP
48 CsrWifiNmeApConverterInit();
53 void CsrWifiRouterTransportDeinit(unifi_priv_t *priv)
55 unifi_trace(priv, UDBG1, "CsrWifiRouterTransportDeinit: \n");
63 void CsrWifiRouterTransportRecv(unifi_priv_t *priv, u8* buffer, size_t bufferLength)
65 CsrMsgConvMsgEntry* msgEntry;
73 /* Decode the prim and message type */
74 CsrUint16Des(&primType, buffer, &offset);
75 CsrUint16Des(&src, buffer, &offset);
76 CsrUint16Des(&dest, buffer, &offset);
77 CsrUint16Des(&msgType, buffer, &offset);
78 offset -= 2; /* Adjust as the Deserialise Function will read this as well */
80 unifi_trace(priv, UDBG4, "CsrWifiRouterTransportRecv: primType=0x%.4X, msgType=0x%.4X, bufferLength=%d\n",
81 primType, msgType, bufferLength);
83 /* Special handling for HOSTIO messages.... */
84 if (primType == CSR_WIFI_HOSTIO_PRIM)
86 CsrWifiRouterCtrlHipReq req = {{CSR_WIFI_ROUTER_CTRL_HIP_REQ, CSR_WIFI_ROUTER_CTRL_PRIM, dest, src, NULL}, 0, NULL, 0, NULL, 0, NULL};
88 req.mlmeCommandLength = bufferLength;
89 req.mlmeCommand = buffer;
91 offset += 8;/* Skip the id, src, dest and slot number */
92 CsrUint16Des(&req.dataRef1Length, buffer, &offset);
93 offset += 2; /* Skip the slot number */
94 CsrUint16Des(&req.dataRef2Length, buffer, &offset);
96 if (req.dataRef1Length)
98 u16 dr1Offset = (bufferLength - req.dataRef2Length) - req.dataRef1Length;
99 req.dataRef1 = &buffer[dr1Offset];
102 if (req.dataRef2Length)
104 u16 dr2Offset = bufferLength - req.dataRef2Length;
105 req.dataRef2 = &buffer[dr2Offset];
108 /* Copy the hip data but strip off the prim type */
109 req.mlmeCommandLength -= (req.dataRef1Length + req.dataRef2Length + 6);
110 req.mlmeCommand = &buffer[6];
112 CsrWifiRouterCtrlHipReqHandler(priv, &req.common);
116 msgEntry = CsrMsgConvFindEntry(primType, msgType);
119 unifi_error(priv, "CsrWifiRouterTransportDeserialiseAndSend can not process the message. primType=0x%.4X, msgType=0x%.4X\n",
121 dump(buffer, bufferLength);
125 msg = (CsrWifiFsmEvent*)(msgEntry->deserFunc)(&buffer[offset], bufferLength - offset);
127 msg->primtype = primType;
130 msg->destination = dest;
134 case CSR_WIFI_ROUTER_CTRL_PRIM:
135 CsrWifiRouterCtrlDownstreamStateHandlers[msg->type - CSR_WIFI_ROUTER_CTRL_PRIM_DOWNSTREAM_LOWEST](priv, msg);
136 CsrWifiRouterCtrlFreeDownstreamMessageContents(CSR_WIFI_ROUTER_CTRL_PRIM, msg);
138 case CSR_WIFI_ROUTER_PRIM:
139 CsrWifiRouterDownstreamStateHandlers[msg->type - CSR_WIFI_ROUTER_PRIM_DOWNSTREAM_LOWEST](priv, msg);
140 CsrWifiRouterFreeDownstreamMessageContents(CSR_WIFI_ROUTER_PRIM, msg);
142 case CSR_WIFI_SME_PRIM:
143 CsrWifiSmeUpstreamStateHandlers[msg->type - CSR_WIFI_SME_PRIM_UPSTREAM_LOWEST](priv, msg);
144 CsrWifiSmeFreeUpstreamMessageContents(CSR_WIFI_SME_PRIM, msg);
146 #ifdef CSR_SUPPORT_WEXT
147 #ifdef CSR_SUPPORT_WEXT_AP
148 case CSR_WIFI_NME_AP_PRIM:
149 CsrWifiNmeApUpstreamStateHandlers(priv, msg);
150 CsrWifiNmeApFreeUpstreamMessageContents(CSR_WIFI_NME_AP_PRIM, msg);
155 unifi_error(priv, "CsrWifiRouterTransportDeserialiseAndSend unhandled prim type 0x%.4X\n", primType);
161 static void CsrWifiRouterTransportSerialiseAndSend(u16 primType, void* msg)
163 CsrWifiFsmEvent* evt = (CsrWifiFsmEvent*)msg;
164 CsrMsgConvMsgEntry* msgEntry;
166 size_t encodeBufferLen = 0;
170 unifi_trace(drvpriv, UDBG4, "CsrWifiRouterTransportSerialiseAndSend: primType=0x%.4X, msgType=0x%.4X\n",
171 primType, evt->type);
173 msgEntry = CsrMsgConvFindEntry(primType, evt->type);
176 unifi_error(drvpriv, "CsrWifiRouterTransportSerialiseAndSend can not process the message. primType=0x%.4X, msgType=0x%.4X\n",
177 primType, evt->type);
181 msgSize = 6 + (msgEntry->sizeofFunc)((void*)msg);
183 encodeBuffer = CsrPmemAlloc(msgSize);
185 /* Encode PrimType */
186 CsrUint16Ser(encodeBuffer, &encodeBufferLen, primType);
187 CsrUint16Ser(encodeBuffer, &encodeBufferLen, evt->source);
188 CsrUint16Ser(encodeBuffer, &encodeBufferLen, evt->destination);
190 (void)(msgEntry->serFunc)(&encodeBuffer[encodeBufferLen], &offset, msg);
191 encodeBufferLen += offset;
193 uf_sme_queue_message(drvpriv, encodeBuffer, encodeBufferLen);
195 /* Do not use msgEntry->freeFunc because the memory is owned by the driver */
199 #if defined(CSR_LOG_ENABLE) && defined(CSR_LOG_INCLUDE_FILE_NAME_AND_LINE_NUMBER)
200 void CsrSchedMessagePutStringLog(CsrSchedQid q, u16 mi, void *mv, u32 line, char *file)
202 void CsrSchedMessagePut(CsrSchedQid q, u16 mi, void *mv)
205 CsrWifiFsmEvent* evt = (CsrWifiFsmEvent*)mv;
206 evt->destination = q;
207 CsrWifiRouterTransportSerialiseAndSend(mi, mv);