SimpleLink CC3120/CC3220 Host Driver  Version 2.0.1.15
Simplifies the implementation of Internet connectivity
netcfg.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 
24 /*****************************************************************************/
25 /* sl_NetCfgSet */
26 /*****************************************************************************/
27 typedef union
28 {
29  SlNetCfgSetGet_t Cmd;
30  _BasicResponse_t Rsp;
31 }_SlNetCfgMsgSet_u;
32 
33 #if _SL_INCLUDE_FUNC(sl_NetCfgSet)
34 
35 static const _SlCmdCtrl_t _SlNetCfgSetCmdCtrl =
36 {
37  SL_OPCODE_DEVICE_NETCFG_SET_COMMAND,
38  (_SlArgSize_t)sizeof(SlNetCfgSetGet_t),
39  (_SlArgSize_t)sizeof(_BasicResponse_t)
40 };
41 
42 _i16 sl_NetCfgSet(const _u16 ConfigId,const _u16 ConfigOpt,const _u16 ConfigLen,const _u8 *pValues)
43 {
44  _SlNetCfgMsgSet_u Msg;
45  _SlCmdExt_t CmdExt;
46 
47  /* verify that this api is allowed. if not allowed then
48  ignore the API execution and return immediately with an error */
49  VERIFY_API_ALLOWED(SL_OPCODE_SILO_NETCFG);
50 
51  _SlDrvResetCmdExt(&CmdExt);
52  CmdExt.TxPayload1Len = (ConfigLen+3) & (~3);
53  CmdExt.pTxPayload1 = (_u8 *)pValues;
54 
55 
56  Msg.Cmd.ConfigId = ConfigId;
57  Msg.Cmd.ConfigLen = ConfigLen;
58  Msg.Cmd.ConfigOpt = ConfigOpt;
59 
60  VERIFY_RET_OK(_SlDrvCmdOp((_SlCmdCtrl_t *)&_SlNetCfgSetCmdCtrl, &Msg, &CmdExt));
61 
62  return (_i16)Msg.Rsp.status;
63 }
64 #endif
65 
66 
67 /*****************************************************************************/
68 /* sl_NetCfgGet */
69 /*****************************************************************************/
70 typedef union
71 {
72  SlNetCfgSetGet_t Cmd;
73  SlNetCfgSetGet_t Rsp;
74 }_SlNetCfgMsgGet_u;
75 
76 #if _SL_INCLUDE_FUNC(sl_NetCfgGet)
77 
78 static const _SlCmdCtrl_t _SlNetCfgGetCmdCtrl =
79 {
80  SL_OPCODE_DEVICE_NETCFG_GET_COMMAND,
81  (_SlArgSize_t)sizeof(SlNetCfgSetGet_t),
82  (_SlArgSize_t)sizeof(SlNetCfgSetGet_t)
83 };
84 
85 _i16 sl_NetCfgGet(const _u16 ConfigId, _u16 *pConfigOpt,_u16 *pConfigLen, _u8 *pValues)
86 {
87  _SlNetCfgMsgGet_u Msg;
88  _SlCmdExt_t CmdExt;
89 
90  /* verify that this api is allowed. if not allowed then
91  ignore the API execution and return immediately with an error */
92  VERIFY_API_ALLOWED(SL_OPCODE_SILO_NETCFG);
93 
94  if (*pConfigLen == 0)
95  {
96  return SL_EZEROLEN;
97  }
98 
99  _SlDrvResetCmdExt(&CmdExt);
100  CmdExt.RxPayloadLen = (_i16)(*pConfigLen);
101  CmdExt.pRxPayload = (_u8 *)pValues;
102 
103  _SlDrvMemZero((void*) &Msg, sizeof(Msg));
104 
105  Msg.Cmd.ConfigLen = *pConfigLen;
106  Msg.Cmd.ConfigId = ConfigId;
107 
108  if( pConfigOpt )
109  {
110  Msg.Cmd.ConfigOpt = (_u16)*pConfigOpt;
111  }
112 
113  VERIFY_RET_OK(_SlDrvCmdOp((_SlCmdCtrl_t *)&_SlNetCfgGetCmdCtrl, &Msg, &CmdExt));
114 
115  if( pConfigOpt )
116  {
117  *pConfigOpt = (_u8)Msg.Rsp.ConfigOpt;
118  }
119  if (CmdExt.RxPayloadLen < CmdExt.ActualRxPayloadLen)
120  {
121  *pConfigLen = (_u8)CmdExt.RxPayloadLen;
122 
123  return SL_ESMALLBUF;
124  }
125  else
126  {
127  *pConfigLen = (_u8)CmdExt.ActualRxPayloadLen;
128  }
129 
130  return Msg.Rsp.Status;
131 }
132 #endif
133 
_i16 sl_NetCfgGet(const _u16 ConfigId, _u16 *pConfigOpt, _u16 *pConfigLen, _u8 *pValues)
Getting network configurations.
Definition: netcfg.c:85
_i16 sl_NetCfgSet(const _u16 ConfigId, const _u16 ConfigOpt, const _u16 ConfigLen, const _u8 *pValues)
Setting network configurations.
Definition: netcfg.c:42