SimpleLink CC3120/CC3220 Host Driver  Version 2.0.1.15
Simplifies the implementation of Internet connectivity
netutil.c
1 /*
2  * Copyright (C) 2016 Texas Instruments Incorporated
3  *
4  * All rights reserved. Property of Texas Instruments Incorporated.
5  * Restricted rights to use, duplicate or disclose this code are
6  * granted through contract.
7  *
8  * The program may not be used without the written permission of
9  * Texas Instruments Incorporated or against the terms and conditions
10  * stipulated in the agreement under which this program has been supplied,
11  * and under no circumstances can it be used with non-TI connectivity device.
12  *
13  */
14 
15 
16 
17 /*****************************************************************************/
18 /* Include files */
19 /*****************************************************************************/
20 #include <ti/drivers/net/wifi/simplelink.h>
21 #include <ti/drivers/net/wifi/source/protocol.h>
22 #include <ti/drivers/net/wifi/source/driver.h>
23 #include <ti/drivers/net/wifi/source/flowcont.h>
24 
25 /*****************************************************************************/
26 /* Internal functions */
27 /*****************************************************************************/
28 
29 /*****************************************************************************/
30 /* API Functions */
31 /*****************************************************************************/
32 
33 
34 typedef struct
35 {
36  _u8 *pOutputValues;
37  _u16 *pOutputLen;
38  _i16 Status;
39 }_SlNetUtilCmdData_t;
40 
41 
42 /******************************************************************************
43 sl_UtilsGet
44 ******************************************************************************/
45 
46 typedef union
47 {
50 } SlNetUtilMsgGet_u;
51 
52 #if _SL_INCLUDE_FUNC(sl_NetUtilGet)
53 
54 const _SlCmdCtrl_t _SlNetUtilGetCmdCtrl =
55 {
56  SL_OPCODE_NETUTIL_GET,
57  sizeof(SlNetUtilSetGet_t),
58  sizeof(SlNetUtilSetGet_t)
59 };
60 
61 _i16 sl_NetUtilGet(const _u16 Option, const _u32 ObjID, _u8 *pValues, _u16 *pValueLen)
62 {
63  SlNetUtilMsgGet_u Msg;
64  _SlCmdExt_t CmdExt;
65 
66  _SlDrvResetCmdExt(&CmdExt);
67  CmdExt.RxPayloadLen = *pValueLen;
68  CmdExt.pRxPayload = (_u8 *)pValues;
69 
70  Msg.Cmd.Option = Option;
71  Msg.Cmd.ObjId = ObjID;
72  Msg.Cmd.ValueLen = *pValueLen;
73 
74  VERIFY_RET_OK(_SlDrvCmdOp((_SlCmdCtrl_t *)&_SlNetUtilGetCmdCtrl, &Msg, &CmdExt));
75 
76  if(CmdExt.RxPayloadLen < CmdExt.ActualRxPayloadLen)
77  {
78  *pValueLen = CmdExt.RxPayloadLen;
79  return SL_ESMALLBUF;
80  }
81  else
82  {
83  *pValueLen = CmdExt.ActualRxPayloadLen;
84  }
85 
86  return (_i16)Msg.Rsp.Status;
87 
88 }
89 #endif
90 
91 
92 /***************************************************************************
93 _SlNetUtilHandleAsync_Cmd - handles NetUtil Cmd response, signalling to
94 a waiting object
95 ****************************************************************************/
96 void _SlNetUtilHandleAsync_Cmd(void *pVoidBuf)
97 {
98  _SlNetUtilCmdData_t *pOutData;
99  SlNetUtilCmdRsp_t *pMsgArgs = (SlNetUtilCmdRsp_t *)_SL_RESP_ARGS_START(pVoidBuf);
100 
101  SL_DRV_PROTECTION_OBJ_LOCK_FOREVER();
102 
103  VERIFY_SOCKET_CB(NULL != g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].pRespArgs);
104 
105  pOutData = (_SlNetUtilCmdData_t*)g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].pRespArgs;
106 
107  pOutData->Status = pMsgArgs->Status;
108 
109  if(SL_RET_CODE_OK == pMsgArgs->Status)
110  {
111  if (*(pOutData->pOutputLen) < pMsgArgs->OutputLen)
112  {
113  pOutData->Status = SL_ESMALLBUF;
114  }
115  else
116  {
117  *(pOutData->pOutputLen) = pMsgArgs->OutputLen;
118 
119  if(*(pOutData->pOutputLen) > 0)
120  {
121  /* copy only the data from the global async buffer */
122  sl_Memcpy(pOutData->pOutputValues, (char*)pMsgArgs + sizeof(SlNetUtilCmdRsp_t), *(pOutData->pOutputLen));
123  }
124  }
125  }
126 
127  _SlDrvSyncObjSignal(&g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].SyncObj);
128  _SlDrvProtectionObjUnLock();
129  return;
130 }
131 
132 
133 /*****************************************************************************
134 sl_NetUtilCmd
135 ******************************************************************************/
136 typedef union
137 {
138  SlNetUtilCmd_t Cmd;
139  _BasicResponse_t Rsp;
140 } SlNetUtilCmdMsg_u;
141 
142 #if _SL_INCLUDE_FUNC(sl_NetUtilCmd)
143 const _SlCmdCtrl_t _SlNetUtilCmdCtrl =
144 {
145  SL_OPCODE_NETUTIL_COMMAND,
146  sizeof(SlNetUtilCmd_t),
147  sizeof(_BasicResponse_t)
148 };
149 
150 
151 _i16 sl_NetUtilCmd(const _u16 Cmd, const _u8 *pAttrib, const _u16 AttribLen,
152  const _u8 *pInputValues, const _u16 InputLen,
153  _u8 *pOutputValues, _u16 *pOutputLen)
154 {
155  _i16 RetVal=0;
156  SlNetUtilCmdMsg_u Msg;
157  _i16 ObjIdx = MAX_CONCURRENT_ACTIONS;
158  _SlCmdExt_t CmdExt;
159  _SlNetUtilCmdData_t OutData;
160 
161 
162  /* prepare the Cmd (control structure and data-buffer) */
163  Msg.Cmd.Cmd = Cmd;
164  Msg.Cmd.AttribLen = AttribLen;
165  Msg.Cmd.InputLen = InputLen;
166  Msg.Cmd.OutputLen = *pOutputLen;
167 
168  _SlDrvResetCmdExt(&CmdExt);
169 
170  if(AttribLen > 0)
171  {
172  CmdExt.pTxPayload1 = (_u8*)pAttrib;
173  CmdExt.TxPayload1Len = AttribLen;
174  }
175 
176  if (InputLen > 0)
177  {
178  CmdExt.pTxPayload2 = (_u8*)pInputValues;
179  CmdExt.TxPayload2Len = InputLen;
180  }
181 
182  /* Set the pointers to be filled upon the async event reception */
183  OutData.pOutputValues = pOutputValues;
184  OutData.pOutputLen = pOutputLen;
185 
186  ObjIdx = _SlDrvProtectAsyncRespSetting((_u8*)&OutData, NETUTIL_CMD_ID, SL_MAX_SOCKETS);
187  if (MAX_CONCURRENT_ACTIONS == ObjIdx)
188  {
189  return SL_POOL_IS_EMPTY;
190  }
191 
192  /* send the command */
193  VERIFY_RET_OK(_SlDrvCmdOp((_SlCmdCtrl_t *)&_SlNetUtilCmdCtrl, &Msg, &CmdExt));
194 
195  if(SL_OS_RET_CODE_OK == (_i16)Msg.Rsp.status)
196  {
197  /* after the async event is signaled, the data will be copied to the pOutputValues buffer */
198  SL_DRV_SYNC_OBJ_WAIT_FOREVER(&g_pCB->ObjPool[ObjIdx].SyncObj);
199 
200  /* the response header status */
201  RetVal = OutData.Status;
202 
203  }
204  else
205  {
206  RetVal = Msg.Rsp.status;
207  }
208  _SlDrvReleasePoolObj((_u8)ObjIdx);
209 
210  return RetVal;
211 }
212 #endif
_i16 sl_NetUtilGet(const _u16 Option, const _u32 ObjID, _u8 *pValues, _u16 *pValueLen)
Function for getting configurations of utilities.
Definition: netutil.c:61
_i16 sl_NetUtilCmd(const _u16 Cmd, const _u8 *pAttrib, const _u16 AttribLen, const _u8 *pInputValues, const _u16 InputLen, _u8 *pOutputValues, _u16 *pOutputLen)
Function for performing utilities-related commands.
Definition: netutil.c:151