1 /*
2  * netcfg.c - CC31xx/CC32xx Host Driver Implementation
3  *
4  * Copyright (C) 2017 Texas Instruments Incorporated - http://www.ti.com/
5  *
6  *
7  *  Redistribution and use in source and binary forms, with or without
8  *  modification, are permitted provided that the following conditions
9  *  are met:
10  *
11  *    Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  *
14  *    Redistributions in binary form must reproduce the above copyright
15  *    notice, this list of conditions and the following disclaimer in the
16  *    documentation and/or other materials provided with the
17  *    distribution.
18  *
19  *    Neither the name of Texas Instruments Incorporated nor the names of
20  *    its contributors may be used to endorse or promote products derived
21  *    from this software without specific prior written permission.
22  *
23  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26  *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
27  *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28  *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
29  *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30  *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31  *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32  *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33  *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34  *
35 */
36 
37 
38 /*****************************************************************************/
39 /* Include files                                                             */
40 /*****************************************************************************/
41 #include <ti/drivers/net/wifi/simplelink.h>
42 #include <ti/drivers/net/wifi/source/protocol.h>
43 #include <ti/drivers/net/wifi/source/driver.h>
44 
45 /*****************************************************************************/
46 /* sl_NetCfgSet */
47 /*****************************************************************************/
48 typedef union
49 {
50     SlNetCfgSetGet_t    Cmd;
51     _BasicResponse_t   Rsp;
52 }_SlNetCfgMsgSet_u;
53 
54 #if _SL_INCLUDE_FUNC(sl_NetCfgSet)
55 
56 static const _SlCmdCtrl_t _SlNetCfgSetCmdCtrl =
57 {
58     SL_OPCODE_DEVICE_NETCFG_SET_COMMAND,
59     (_SlArgSize_t)sizeof(SlNetCfgSetGet_t),
60     (_SlArgSize_t)sizeof(_BasicResponse_t)
61 };
62 
sl_NetCfgSet(const _u16 ConfigId,const _u16 ConfigOpt,const _u16 ConfigLen,const _u8 * pValues)63 _i16 sl_NetCfgSet(const _u16 ConfigId,const _u16 ConfigOpt,const _u16 ConfigLen,const _u8 *pValues)
64 {
65     _SlNetCfgMsgSet_u         Msg;
66     _SlCmdExt_t               CmdExt;
67 
68     /* verify that this api is allowed. if not allowed then
69     ignore the API execution and return immediately with an error */
70     VERIFY_API_ALLOWED(SL_OPCODE_SILO_NETCFG);
71 
72     _SlDrvResetCmdExt(&CmdExt);
73     CmdExt.TxPayload1Len = (ConfigLen+3) & (~3);
74     CmdExt.pTxPayload1 = (_u8 *)pValues;
75 
76     Msg.Cmd.ConfigId    = ConfigId;
77     Msg.Cmd.ConfigLen   = ConfigLen;
78     Msg.Cmd.ConfigOpt   = ConfigOpt;
79 
80     VERIFY_RET_OK(_SlDrvCmdOp((_SlCmdCtrl_t *)&_SlNetCfgSetCmdCtrl, &Msg, &CmdExt));
81 
82     return (_i16)Msg.Rsp.status;
83 }
84 #endif
85 
86 /*****************************************************************************/
87 /* sl_NetCfgGet */
88 /*****************************************************************************/
89 typedef union
90 {
91     SlNetCfgSetGet_t        Cmd;
92     SlNetCfgSetGet_t        Rsp;
93 }_SlNetCfgMsgGet_u;
94 
95 #if _SL_INCLUDE_FUNC(sl_NetCfgGet)
96 
97 static const _SlCmdCtrl_t _SlNetCfgGetCmdCtrl =
98 {
99     SL_OPCODE_DEVICE_NETCFG_GET_COMMAND,
100     (_SlArgSize_t)sizeof(SlNetCfgSetGet_t),
101     (_SlArgSize_t)sizeof(SlNetCfgSetGet_t)
102 };
103 
sl_NetCfgGet(const _u16 ConfigId,_u16 * pConfigOpt,_u16 * pConfigLen,_u8 * pValues)104 _i16 sl_NetCfgGet(const _u16 ConfigId, _u16 *pConfigOpt,_u16 *pConfigLen, _u8 *pValues)
105 {
106     _SlNetCfgMsgGet_u         Msg;
107     _SlCmdExt_t               CmdExt;
108 
109     /* verify that this api is allowed. if not allowed then
110     ignore the API execution and return immediately with an error */
111     VERIFY_API_ALLOWED(SL_OPCODE_SILO_NETCFG);
112 
113     if (*pConfigLen == 0)
114     {
115         return SL_EZEROLEN;
116     }
117 
118     _SlDrvResetCmdExt(&CmdExt);
119     CmdExt.RxPayloadLen = (_i16)(*pConfigLen);
120     CmdExt.pRxPayload = (_u8 *)pValues;
121 
122     _SlDrvMemZero((void*) &Msg, sizeof(Msg));
123 
124     Msg.Cmd.ConfigLen    = *pConfigLen;
125     Msg.Cmd.ConfigId     = ConfigId;
126 
127     if( pConfigOpt )
128     {
129         Msg.Cmd.ConfigOpt   = (_u16)*pConfigOpt;
130     }
131 
132     VERIFY_RET_OK(_SlDrvCmdOp((_SlCmdCtrl_t *)&_SlNetCfgGetCmdCtrl, &Msg, &CmdExt));
133 
134     if( pConfigOpt )
135     {
136         *pConfigOpt = (_u8)Msg.Rsp.ConfigOpt;
137     }
138     if (CmdExt.RxPayloadLen < CmdExt.ActualRxPayloadLen)
139     {
140         *pConfigLen = (_u8)CmdExt.RxPayloadLen;
141         return SL_ESMALLBUF;
142     }
143     else
144     {
145         *pConfigLen = (_u8)CmdExt.ActualRxPayloadLen;
146     }
147 
148     return Msg.Rsp.Status;
149 }
150 #endif
151 
152