DeepCover Embedded Security in IoT: Public-key Secured Data Paths
Dependencies: MaximInterface
netcfg.c
00001 /* 00002 * netcfg.c - CC31xx/CC32xx Host Driver Implementation 00003 * 00004 * Copyright (C) 2015 Texas Instruments Incorporated - http://www.ti.com/ 00005 * 00006 * 00007 * Redistribution and use in source and binary forms, with or without 00008 * modification, are permitted provided that the following conditions 00009 * are met: 00010 * 00011 * Redistributions of source code must retain the above copyright 00012 * notice, this list of conditions and the following disclaimer. 00013 * 00014 * Redistributions in binary form must reproduce the above copyright 00015 * notice, this list of conditions and the following disclaimer in the 00016 * documentation and/or other materials provided with the 00017 * distribution. 00018 * 00019 * Neither the name of Texas Instruments Incorporated nor the names of 00020 * its contributors may be used to endorse or promote products derived 00021 * from this software without specific prior written permission. 00022 * 00023 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00024 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00025 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 00026 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 00027 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 00028 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 00029 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 00030 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 00031 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00032 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 00033 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00034 * 00035 */ 00036 00037 00038 00039 /*****************************************************************************/ 00040 /* Include files */ 00041 /*****************************************************************************/ 00042 #include "simplelink.h" 00043 #include "protocol.h" 00044 #include "driver.h" 00045 00046 /*****************************************************************************/ 00047 /* sl_NetCfgSet */ 00048 /*****************************************************************************/ 00049 typedef union 00050 { 00051 _NetCfgSetGet_t Cmd; 00052 _BasicResponse_t Rsp; 00053 }_SlNetCfgMsgSet_u; 00054 00055 #if _SL_INCLUDE_FUNC(sl_NetCfgSet) 00056 00057 static const _SlCmdCtrl_t _SlNetCfgSetCmdCtrl = 00058 { 00059 SL_OPCODE_DEVICE_NETCFG_SET_COMMAND, 00060 (_SlArgSize_t)sizeof(_NetCfgSetGet_t), 00061 (_SlArgSize_t)sizeof(_BasicResponse_t) 00062 }; 00063 00064 _i32 sl_NetCfgSet(const _u8 ConfigId ,const _u8 ConfigOpt,const _u8 ConfigLen,const _u8 *pValues) 00065 { 00066 _SlNetCfgMsgSet_u Msg; 00067 _SlCmdExt_t CmdExt; 00068 00069 /* verify no erorr handling in progress. if in progress than 00070 ignore the API execution and return immediately with an error */ 00071 VERIFY_NO_ERROR_HANDLING_IN_PROGRESS(); 00072 00073 _SlDrvResetCmdExt(&CmdExt); 00074 CmdExt.TxPayloadLen = (ConfigLen+3) & (~3); 00075 CmdExt.pTxPayload = (_u8 *)pValues; 00076 00077 00078 Msg.Cmd.ConfigId = ConfigId; 00079 Msg.Cmd.ConfigLen = ConfigLen; 00080 Msg.Cmd.ConfigOpt = ConfigOpt; 00081 00082 VERIFY_RET_OK(_SlDrvCmdOp((_SlCmdCtrl_t *)&_SlNetCfgSetCmdCtrl, &Msg, &CmdExt)); 00083 00084 return (_i16)Msg.Rsp.status; 00085 } 00086 #endif 00087 00088 00089 /*****************************************************************************/ 00090 /* sl_NetCfgGet */ 00091 /*****************************************************************************/ 00092 typedef union 00093 { 00094 _NetCfgSetGet_t Cmd; 00095 _NetCfgSetGet_t Rsp; 00096 }_SlNetCfgMsgGet_u; 00097 00098 #if _SL_INCLUDE_FUNC(sl_NetCfgGet) 00099 00100 static const _SlCmdCtrl_t _SlNetCfgGetCmdCtrl = 00101 { 00102 SL_OPCODE_DEVICE_NETCFG_GET_COMMAND, 00103 (_SlArgSize_t)sizeof(_NetCfgSetGet_t), 00104 (_SlArgSize_t)sizeof(_NetCfgSetGet_t) 00105 }; 00106 00107 _i32 sl_NetCfgGet(const _u8 ConfigId, _u8 *pConfigOpt,_u8 *pConfigLen, _u8 *pValues) 00108 { 00109 _SlNetCfgMsgGet_u Msg; 00110 _SlCmdExt_t CmdExt; 00111 00112 /* verify no erorr handling in progress. if in progress than 00113 ignore the API execution and return immediately with an error */ 00114 VERIFY_NO_ERROR_HANDLING_IN_PROGRESS(); 00115 00116 if (*pConfigLen == 0) 00117 { 00118 return SL_EZEROLEN; 00119 } 00120 00121 _SlDrvResetCmdExt(&CmdExt); 00122 CmdExt.RxPayloadLen = (_i16)(*pConfigLen); 00123 CmdExt.pRxPayload = (_u8 *)pValues; 00124 Msg.Cmd.ConfigLen = *pConfigLen; 00125 Msg.Cmd.ConfigId = ConfigId; 00126 00127 if( pConfigOpt ) 00128 { 00129 Msg.Cmd.ConfigOpt = (_u16)*pConfigOpt; 00130 } 00131 VERIFY_RET_OK(_SlDrvCmdOp((_SlCmdCtrl_t *)&_SlNetCfgGetCmdCtrl, &Msg, &CmdExt)); 00132 00133 if( pConfigOpt ) 00134 { 00135 *pConfigOpt = (_u8)Msg.Rsp.ConfigOpt; 00136 } 00137 if (CmdExt.RxPayloadLen < CmdExt.ActualRxPayloadLen) 00138 { 00139 *pConfigLen = (_u8)CmdExt.RxPayloadLen; 00140 if( SL_MAC_ADDRESS_GET == ConfigId ) 00141 { 00142 return SL_RET_CODE_OK; /* sp fix */ 00143 } 00144 else 00145 { 00146 return SL_ESMALLBUF; 00147 } 00148 } 00149 else 00150 { 00151 *pConfigLen = (_u8)CmdExt.ActualRxPayloadLen; 00152 } 00153 00154 return (_i32)Msg.Rsp.Status; 00155 } 00156 #endif 00157
Generated on Tue Jul 12 2022 12:06:48 by 1.7.2