SimpleLink CC3120/CC3220 Host Driver  Version 2.0.1.15
Simplifies the implementation of Internet connectivity
NetUtil

Networking related commands and configuration. More...

Functions

_i32 sl_NetUtilSet (const _u16 Option, const _u32 ObjID, const _u8 *pValues, const _u16 ValueLen)
 Function for setting configurations of utilities. More...
 
_i16 sl_NetUtilGet (const _u16 Option, const _u32 ObjID, _u8 *pValues, _u16 *pValueLen)
 Function for getting configurations of utilities. More...
 
_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. More...
 

Detailed Description

Networking related commands and configuration.

Function Documentation

_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.

Parameters
[in]CmdIdentifier of the specific Command to perform
  • SL_NETUTIL_CRYPTO_CMD_INSTALL_OP
    Install / Uninstall key pairs in one or more of the crypto utils key-pair management mechanism.
    Key Must be an ECC key-pair using SECP256R1 curve and already programmed to file system, in DER format.
    Key installation is persistent.
  • SL_NETUTIL_CRYPTO_CMD_TEMP_KEYS
    Creates or removes a temporary key pair.
    Key pair is created internally by the NWP. Key pair is not persistent over power cycle.
  • SL_NETUTIL_CRYPTO_CMD_SIGN_MSG
    Signs with a digital signature a data buffer using ECDSA algorithm.
  • SL_NETUTIL_CRYPTO_CMD_VERIFY_MSG
    Verify a digital signature given with a data buffer using ECDSA algorithm.
[in]pAttribPointer to the buffer holding the Attribute values
[in]AttribLenLength of the Attribute-values
[in]pInputValuesPointer to the buffer holding the input-value
[in]InputLenLength of the input-value
[out]pOutputValuesPointer to the buffer that the application allocates, and will hold the received data.
[in,out]pOutputLenLength of the output-value
On input - provides the length of the buffer that the application allocates, and will hold the output
On output - provides the actual length of the received output-values
Returns
Zero on success, or negative error code on failure
See also
sl_NetUtilGet sl_NetUtilSet
Note
Warning
Examples
  • SL_NETUTIL_CRYPTO_CMD_INSTALL_OP (install / uninstall crypto keys):
    1 // Install a key
    2 SlNetUtilCryptoCmdKeyMgnt_t keyAttrib;
    3 SlNetUtilCryptoPubKeyInfo_t *pInfoKey;
    4 uint8_t name[FILE_NAME_SIZE];
    5 int32_t Status;
    6 int16_t resultLen;
    7 
    8 keyAttrib.ObjId = 5; // Key would be stored at index 5
    9 keyAttrib.SubCmd = SL_NETUTIL_CRYPTO_INSTALL_SUB_CMD;
    10 pInfoKey->KeyAlgo = SL_NETUTIL_CRYPTO_PUB_KEY_ALGO_EC;
    11 pInfoKey->KeyParams.EcParams.CurveType = SL_NETUTIL_CRYPTO_EC_CURVE_TYPE_NAMED; //ECC curve
    12 pInfoKey->KeyParams.EcParams.CurveParams.NamedCurveParams = SL_NETUTIL_CRYPTO_EC_NAMED_CURVE_SECP256R1; // SECP256R1 curve only.
    13 
    14 pInfoKey->CertFileNameLen = 0;
    15 name = ((uint8_t *)pInfoKey) + sizeof(SlNetUtilCryptoPubKeyInfo_t);
    16 name += pInfoKey->CertFileNameLen;
    17 strcpy((char *)name, "extkey.der"); // Private key name in file system.
    18 pInfoKey->KeyFileNameLen = strlen("extkey.der")+1;
    19 
    20 Status = sl_NetUtilCmd(SL_NETUTIL_CRYPTO_CMD_INSTALL_OP,
    21  (uint8_t *)&keyAttrib, sizeof(SlNetUtilCryptoCmdKeyMgnt_t),
    22  (uint8_t *)pInfo,
    23  sizeof(SlNetUtilCryptoPubKeyInfo_t) + pInfoKey->KeyFileNameLen,
    24  NULL, &resultLen);
    25 
    26 // Uninstall the Key:
    27 resultLen = 0;
    28 keyAttrib.ObjId = 5;
    29 keyAttrib.SubCmd = SL_NETUTIL_CRYPTO_UNINSTALL_SUB_CMD;
    30 
    31 Status = sl_NetUtilCmd(SL_NETUTIL_CRYPTO_CMD_INSTALL_OP, (uint8_t *)&keyAttrib,
    32  sizeof(SlNetUtilCryptoCmdKeyMgnt_t), NULL, 0 , NULL, &resultLen);
  • SL_NETUTIL_CRYPTO_CMD_TEMP_KEYS, (Create a temporary key ):
    1 SlNetUtilCryptoCmdKeyMgnt_t keyAttrib;
    2 int32_t Status;
    3 uint16_t resultLen;
    4 keyAttrib.ObjId = 1; // key index is 1
    5 keyAttrib.SubCmd = SL_NETUTIL_CRYPTO_TEMP_KEYS_CREATE;
    6 
    7 Status = sl_NetUtilCmd(SL_NETUTIL_CRYPTO_CMD_TEMP_KEYS,
    8  (uint8_t *)&keyAttrib, sizeof(SlNetUtilCryptoCmdKeyMgnt_t),
    9  NULL, 0 , NULL, &resultLen);
    - SL_NETUTIL_CRYPTO_CMD_TEMP_KEYS, (Create a temporary key ):
    
    1 SlNetUtilCryptoCmdKeyMgnt_t keyAttrib;
    2 int32_t Status;
    3 uint16_t resultLen;
    4 keyAttrib.ObjId = 1; // key index is 1
    5 keyAttrib.SubCmd = SL_NETUTIL_CRYPTO_TEMP_KEYS_CREATE;
    6 
    7 Status = sl_NetUtilCmd(SL_NETUTIL_CRYPTO_CMD_TEMP_KEYS,
    8  (uint8_t *)&keyAttrib, sizeof(SlNetUtilCryptoCmdKeyMgnt_t),
    9  NULL, 0 , NULL, &resultLen);
        - SL_NETUTIL_CRYPTO_CMD_SIGN_MSG, (Sign a data buffer):
    
    1 int32_t Status;
    2 int32_t configLen;
    3 uint8_t messageBuff[1500];
    4 uint8_t sig_buf[256]; // This buffer shall contain the digital signature.
    5 SlNetUtilCryptoCmdSignAttrib_t signAttrib;
    6 
    7 signAttrib.Flags = 0;
    8 signAttrib.ObjId = 3;
    9 signAttrib.SigType = SL_NETUTIL_CRYPTO_SIG_SHAwECDSA; // this is the only type supported
    10 configLen = 255;
    11 
    12 Status = sl_NetUtilCmd(SL_NETUTIL_CRYPTO_CMD_SIGN_MSG, (uint8_t *)&signAttrib,
    13  sizeof(SlNetUtilCryptoCmdSignAttrib_t),
    14  messageBuff, sizeof(messageBuf), sig_buf, &configLen);
            - SL_NETUTIL_CRYPTO_CMD_VERIFY_MSG, (Verify a data buffer):
    
    1 int32_t Status;
    2 int32_t configLen;
    3 uint8_t verifyBuf[2048];
    4 uint8_t messageBuff[1500];
    5 uint8_t sig_buf[256]; // This buffer contains the digital signature.
    6 int32_t verifyResult;
    7 SlNetUtilCryptoCmdVerifyAttrib_t verAttrib;
    8 
    9 memcpy(verifyBuf, messageBuf, sizeof(messageBuf)); // copy the message to verify buffer.
    10 memcpy(verifyBuf + sizeof(messageBuff), sig_buf, configLen); // Append the signature to message buffer.
    11 
    12 verAttrib.Flags = 0;
    13 verAttrib.ObjId = 3;
    14 verAttrib.SigType = SL_NETUTIL_CRYPTO_SIG_SHAwECDSA; // this is the only type supported
    15 verAttrib.MsgLen = sizeof(messageBuff);
    16 verAttrib.SigLen = configLen;
    17 configLen = 255;
    18 resultLen = 4;
    19 
    20 Status = sl_NetUtilCmd(SL_NETUTIL_CRYPTO_CMD_VERIFY_MSG, (uint8_t *)&verAttrib,
    21  sizeof(SlNetUtilCryptoCmdVerifyAttrib_t),
    22  verifyBuf, sizeof(messageBuf) + configLen,
    23  (uint8_t *)&verifyResult , &resultLen);

Definition at line 151 of file netutil.c.

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 }
_i16 sl_NetUtilGet ( const _u16  Option,
const _u32  ObjID,
_u8 *  pValues,
_u16 *  pValueLen 
)

Function for getting configurations of utilities.

Parameters
[in]OptionIdentifier of the specific "get" operation to perform
  • SL_NETUTIL_CRYPTO_PUBLIC_KEY
    Used to retrieve the public key from an installed key-pair.
    Saved in a certain index.
  • SL_NETUTIL_TRUE_RANDOM
    Generates a random number using the internal TRNG of the NWP.
[in]ObjIDID of the relevant object that this set operation will be performed on
[in,out]pValueLenPointer to the length of the value parameter
On input - provides the length of the buffer that the application allocates, and will hold the output
On output - provides the actual length of the received data
[out]pValuesPointer to the buffer that the application allocates, and will hold the received data.
Returns
Zero on success, or negative error code on failure.
See also
sl_NetUtilSet sl_NetUtilCmd
Note
Warning
Examples
        - SL_NETUTIL_CRYPTO_PUBLIC_KEY:
1 int16_t Status;
2 uint8_t configOpt = 0;
3 uint32_t objId = 0;
4 uint16_t configLen = 0;
5 uint8_t key_buf[256];
6 
7 configOpt = SL_NETUTIL_CRYPTO_PUBLIC_KEY;
8 
9 objId = 1;
10 configLen = 255;
11 //get the Public key
12 Status = sl_NetUtilGet(configOpt, objId, key_buf, &configLen);
        - SL_NETUTIL_TRUE_RANDOM:
1 uint32_t randNum;
2 int32_t len = sizeof(uint32_t);
3 
4 sl_NetUtilGet(SL_NETUTIL_TRUE_RANDOM, 0, (uint8_t *)&randNum, &len);

Definition at line 61 of file netutil.c.

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 }
_i32 sl_NetUtilSet ( const _u16  Option,
const _u32  ObjID,
const _u8 *  pValues,
const _u16  ValueLen 
)

Function for setting configurations of utilities.

Parameters
[in]OptionIdentifier of the specific "set" operation to perform
[in]ObjIDID of the relevant object that this set operation will be performed on
[in]ValueLenLength of the value parameter
[in]pValuesPointer to the buffer holding the configurations values
Returns
Zero on success, or negative error code on failure
See also
sl_NetUtilGet sl_NetUtilCmd
Note
Warning

Data Structure Documentation

struct SlNetUtilCryptoEcCustomCurveParam_t

Definition at line 147 of file netutil.h.

Data Fields
_u8 Padding[4]
union SlNetUtilCryptoEcCurveParams_u

Definition at line 154 of file netutil.h.

Data Fields
SlNetUtilCryptoEcCustomCurveParam_t CustomCurveParams
_u8 NamedCurveParams
struct SlNetUtilCryptoEcKeyParams_t

Definition at line 172 of file netutil.h.

Data Fields
SlNetUtilCryptoEcCurveParams_u CurveParams
_u8 CurveType
union SlNetUtilCryptoPubKeyParams_u

Definition at line 179 of file netutil.h.

Data Fields
SlNetUtilCryptoEcKeyParams_t EcParams
struct SlNetUtilCryptoPubKeyInfo_t

Definition at line 191 of file netutil.h.

Data Fields
_u8 CertFileNameLen
_u8 KeyAlgo
_u8 KeyFileNameLen
SlNetUtilCryptoPubKeyParams_u KeyParams
struct SlNetUtilCryptoCmdSignAttrib_t

Definition at line 203 of file netutil.h.

Data Fields
_u32 Flags
_u32 ObjId
_u32 SigType
struct SlNetUtilCryptoCmdVerifyAttrib_t

Definition at line 212 of file netutil.h.

Data Fields
_u32 Flags
_u16 MsgLen
_u32 ObjId
_u16 SigLen
_u32 SigType
struct SlNetUtilCryptoCmdCreateCertAttrib_t

Definition at line 222 of file netutil.h.

Data Fields
_u32 Flags
_u32 ObjId
_u16 SubCmd
struct SlNetUtilCryptoCmdKeyMgnt_t

Definition at line 231 of file netutil.h.

Data Fields
_u32 Flags
_u32 ObjId
_u16 SubCmd