SimpleLink CC3120/CC3220 Host Driver  Version 2.0.1.18
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

§ sl_NetUtilCmd()

_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):
    // Install a key
    uint8_t name[FILE_NAME_SIZE];
    int32_t Status;
    int16_t resultLen;
    keyAttrib.ObjId = 5; // Key would be stored at index 5
    keyAttrib.SubCmd = SL_NETUTIL_CRYPTO_INSTALL_SUB_CMD;
    pInfoKey->KeyAlgo = SL_NETUTIL_CRYPTO_PUB_KEY_ALGO_EC;
    pInfoKey->KeyParams.EcParams.CurveType = SL_NETUTIL_CRYPTO_EC_CURVE_TYPE_NAMED; //ECC curve
    pInfoKey->KeyParams.EcParams.CurveParams.NamedCurveParams = SL_NETUTIL_CRYPTO_EC_NAMED_CURVE_SECP256R1; // SECP256R1 curve only.
    pInfoKey->CertFileNameLen = 0;
    name = ((uint8_t *)pInfoKey) + sizeof(SlNetUtilCryptoPubKeyInfo_t);
    name += pInfoKey->CertFileNameLen;
    strcpy((char *)name, "extkey.der"); // Private key name in file system.
    pInfoKey->KeyFileNameLen = strlen("extkey.der")+1;
    Status = sl_NetUtilCmd(SL_NETUTIL_CRYPTO_CMD_INSTALL_OP,
    (uint8_t *)&keyAttrib, sizeof(SlNetUtilCryptoCmdKeyMgnt_t),
    (uint8_t *)pInfo,
    sizeof(SlNetUtilCryptoPubKeyInfo_t) + pInfoKey->KeyFileNameLen,
    NULL, &resultLen);
    // Uninstall the Key:
    resultLen = 0;
    keyAttrib.ObjId = 5;
    keyAttrib.SubCmd = SL_NETUTIL_CRYPTO_UNINSTALL_SUB_CMD;
    Status = sl_NetUtilCmd(SL_NETUTIL_CRYPTO_CMD_INSTALL_OP, (uint8_t *)&keyAttrib,
    sizeof(SlNetUtilCryptoCmdKeyMgnt_t), NULL, 0 , NULL, &resultLen);
  • SL_NETUTIL_CRYPTO_CMD_TEMP_KEYS, (Create a temporary key ):
    int32_t Status;
    uint16_t resultLen;
    keyAttrib.ObjId = 1; // key index is 1
    keyAttrib.SubCmd = SL_NETUTIL_CRYPTO_TEMP_KEYS_CREATE;
    Status = sl_NetUtilCmd(SL_NETUTIL_CRYPTO_CMD_TEMP_KEYS,
    (uint8_t *)&keyAttrib, sizeof(SlNetUtilCryptoCmdKeyMgnt_t),
    NULL, 0 , NULL, &resultLen);
    - SL_NETUTIL_CRYPTO_CMD_TEMP_KEYS, (Create a temporary key ):
    
    int32_t Status;
    uint16_t resultLen;
    keyAttrib.ObjId = 1; // key index is 1
    keyAttrib.SubCmd = SL_NETUTIL_CRYPTO_TEMP_KEYS_CREATE;
    Status = sl_NetUtilCmd(SL_NETUTIL_CRYPTO_CMD_TEMP_KEYS,
    (uint8_t *)&keyAttrib, sizeof(SlNetUtilCryptoCmdKeyMgnt_t),
    NULL, 0 , NULL, &resultLen);
        - SL_NETUTIL_CRYPTO_CMD_SIGN_MSG, (Sign a data buffer):
    
    int32_t Status;
    int32_t configLen;
    uint8_t messageBuff[1500];
    uint8_t sig_buf[256]; // This buffer shall contain the digital signature.
    signAttrib.Flags = 0;
    signAttrib.ObjId = 3;
    signAttrib.SigType = SL_NETUTIL_CRYPTO_SIG_SHAwECDSA; // this is the only type supported
    configLen = 255;
    Status = sl_NetUtilCmd(SL_NETUTIL_CRYPTO_CMD_SIGN_MSG, (uint8_t *)&signAttrib,
    messageBuff, sizeof(messageBuf), sig_buf, &configLen);
            - SL_NETUTIL_CRYPTO_CMD_VERIFY_MSG, (Verify a data buffer):
    
    int32_t Status;
    int32_t configLen;
    uint8_t verifyBuf[2048];
    uint8_t messageBuff[1500];
    uint8_t sig_buf[256]; // This buffer contains the digital signature.
    int32_t verifyResult;
    memcpy(verifyBuf, messageBuf, sizeof(messageBuf)); // copy the message to verify buffer.
    memcpy(verifyBuf + sizeof(messageBuff), sig_buf, configLen); // Append the signature to message buffer.
    verAttrib.Flags = 0;
    verAttrib.ObjId = 3;
    verAttrib.SigType = SL_NETUTIL_CRYPTO_SIG_SHAwECDSA; // this is the only type supported
    verAttrib.MsgLen = sizeof(messageBuff);
    verAttrib.SigLen = configLen;
    configLen = 255;
    resultLen = 4;
    Status = sl_NetUtilCmd(SL_NETUTIL_CRYPTO_CMD_VERIFY_MSG, (uint8_t *)&verAttrib,
    verifyBuf, sizeof(messageBuf) + configLen,
    (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  _SlDrvMemZero(&OutData, sizeof(_SlNetUtilCmdData_t));
170 
171  if(AttribLen > 0)
172  {
173  CmdExt.pTxPayload1 = (_u8*)pAttrib;
174  CmdExt.TxPayload1Len = AttribLen;
175  }
176 
177  if (InputLen > 0)
178  {
179  CmdExt.pTxPayload2 = (_u8*)pInputValues;
180  CmdExt.TxPayload2Len = InputLen;
181  }
182 
183  /* Set the pointers to be filled upon the async event reception */
184  OutData.pOutputValues = pOutputValues;
185  OutData.pOutputLen = pOutputLen;
186 
187  ObjIdx = _SlDrvProtectAsyncRespSetting((_u8*)&OutData, NETUTIL_CMD_ID, SL_MAX_SOCKETS);
188  if (MAX_CONCURRENT_ACTIONS == ObjIdx)
189  {
190  return SL_POOL_IS_EMPTY;
191  }
192 
193  /* send the command */
194  VERIFY_RET_OK(_SlDrvCmdOp((_SlCmdCtrl_t *)&_SlNetUtilCmdCtrl, &Msg, &CmdExt));
195 
196  if(SL_OS_RET_CODE_OK == (_i16)Msg.Rsp.status)
197  {
198  /* after the async event is signaled, the data will be copied to the pOutputValues buffer */
199  SL_DRV_SYNC_OBJ_WAIT_FOREVER(&g_pCB->ObjPool[ObjIdx].SyncObj);
200 
201  /* the response header status */
202  RetVal = OutData.Status;
203 
204  }
205  else
206  {
207  RetVal = Msg.Rsp.status;
208  }
209  _SlDrvReleasePoolObj((_u8)ObjIdx);
210 
211  return RetVal;
212 }

§ sl_NetUtilGet()

_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:
int16_t Status;
uint8_t configOpt = 0;
uint32_t objId = 0;
uint16_t configLen = 0;
uint8_t key_buf[256];
configOpt = SL_NETUTIL_CRYPTO_PUBLIC_KEY;
objId = 1;
configLen = 255;
//get the Public key
Status = sl_NetUtilGet(configOpt, objId, key_buf, &configLen);
        - SL_NETUTIL_TRUE_RANDOM:
uint32_t randNum;
int32_t len = sizeof(uint32_t);
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 }

§ sl_NetUtilSet()

_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

§ SlNetUtilCryptoEcCustomCurveParam_t

struct SlNetUtilCryptoEcCustomCurveParam_t

Definition at line 147 of file netutil.h.

Data Fields
_u8 Padding[4]

§ SlNetUtilCryptoEcCurveParams_u

union SlNetUtilCryptoEcCurveParams_u

Definition at line 154 of file netutil.h.

Data Fields
SlNetUtilCryptoEcCustomCurveParam_t CustomCurveParams
_u8 NamedCurveParams

§ SlNetUtilCryptoEcKeyParams_t

struct SlNetUtilCryptoEcKeyParams_t

Definition at line 172 of file netutil.h.

Data Fields
SlNetUtilCryptoEcCurveParams_u CurveParams
_u8 CurveType

§ SlNetUtilCryptoPubKeyParams_u

union SlNetUtilCryptoPubKeyParams_u

Definition at line 179 of file netutil.h.

Data Fields
SlNetUtilCryptoEcKeyParams_t EcParams

§ SlNetUtilCryptoPubKeyInfo_t

struct SlNetUtilCryptoPubKeyInfo_t

Definition at line 191 of file netutil.h.

Data Fields
_u8 CertFileNameLen
_u8 KeyAlgo
_u8 KeyFileNameLen
SlNetUtilCryptoPubKeyParams_u KeyParams

§ SlNetUtilCryptoCmdSignAttrib_t

struct SlNetUtilCryptoCmdSignAttrib_t

Definition at line 203 of file netutil.h.

Data Fields
_u32 Flags
_u32 ObjId
_u32 SigType

§ SlNetUtilCryptoCmdVerifyAttrib_t

struct SlNetUtilCryptoCmdVerifyAttrib_t

Definition at line 212 of file netutil.h.

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

§ SlNetUtilCryptoCmdCreateCertAttrib_t

struct SlNetUtilCryptoCmdCreateCertAttrib_t

Definition at line 222 of file netutil.h.

Data Fields
_u32 Flags
_u32 ObjId
_u16 SubCmd

§ SlNetUtilCryptoCmdKeyMgnt_t

struct SlNetUtilCryptoCmdKeyMgnt_t

Definition at line 231 of file netutil.h.

Data Fields
_u32 Flags
_u32 ObjId
_u16 SubCmd