SimpleLink CC31xx/CC32xx Host Driver  Version 3.0.1.55
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.
  • SL_NETUTIL_CMD_ARP_LOOKUP
    Mapping MAC address to IPv4 or IPv6 address.
[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
The host driver API sl_NetUtilCmd is not valid for use with the CC3220R device.
The SL_NETUTIL_CMD_ARP_LOOKUP cmd is only valid for the CC3235S/SF devices.
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, if other hash algorithm
    // is wanted, SL_NETUTIL_CRYPTO_SIG_DIGESTwECDSA is used and
    // the verifyBuf should be the digest and MsgLen should be
    // the digest size
    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);

         - SL_NETUTIL_CMD_ARP_LOOKUP, (Mapping MAC address to IPv4 or IPv6 address), CC3235S/SF devices only:
_u32 ipv4;
_u8 macAddr[6];
_u16 outLen = sizeof(macAddr);
_i16 status;
ipv4 = SL_IPV4_VAL(192,168,178,43);
arpAttr.NumOfRetries = 3;
arpAttr.Timeout = 50;
status = sl_NetUtilCmd(SL_NETUTIL_CMD_ARP_LOOKUP, (uint8_t *)&arpAttr, sizeof(arpAttr), (_u8*)&ipv4 , sizeof(ipv4), macAddr,&outLen);
if(status != 0)
{
// MAC was not found
}
else
{
// IP address mapped to MAC
}


Definition at line 162 of file netutil.c.

165 {
166  _i16 RetVal=0;
167  SlNetUtilCmdMsg_u Msg;
168  _i16 ObjIdx = MAX_CONCURRENT_ACTIONS;
169  _SlCmdExt_t CmdExt;
170  _SlNetUtilCmdData_t OutData;
171 
172  /* prepare the Cmd (control structure and data-buffer) */
173  Msg.Cmd.Cmd = Cmd;
174  Msg.Cmd.AttribLen = AttribLen;
175  Msg.Cmd.InputLen = InputLen;
176  Msg.Cmd.OutputLen = *pOutputLen;
177 
178  _SlDrvResetCmdExt(&CmdExt);
179  _SlDrvMemZero(&OutData, sizeof(_SlNetUtilCmdData_t));
180 
181  if(AttribLen > 0)
182  {
183  CmdExt.pTxPayload1 = (_u8*)pAttrib;
184  CmdExt.TxPayload1Len = AttribLen;
185  }
186 
187  if (InputLen > 0)
188  {
189  CmdExt.pTxPayload2 = (_u8*)pInputValues;
190  CmdExt.TxPayload2Len = InputLen;
191  }
192 
193  /* Set the pointers to be filled upon the async event reception */
194  OutData.pOutputValues = pOutputValues;
195  OutData.pOutputLen = pOutputLen;
196 
197  ObjIdx = _SlDrvProtectAsyncRespSetting((_u8*)&OutData, NETUTIL_CMD_ID, SL_MAX_SOCKETS);
198  if (MAX_CONCURRENT_ACTIONS == ObjIdx)
199  {
200  return SL_POOL_IS_EMPTY;
201  }
202 
203  /* send the command */
204  VERIFY_RET_OK(_SlDrvCmdOp((_SlCmdCtrl_t *)&_SlNetUtilCmdCtrl, &Msg, &CmdExt));
205 
206  if(SL_OS_RET_CODE_OK == (_i16)Msg.Rsp.status)
207  {
208  /* after the async event is signaled, the data will be copied to the pOutputValues buffer */
209  RetVal = _SlDrvWaitForInternalAsyncEvent(ObjIdx, 0, 0);
210 
211  if(RetVal >= 0)
212  {
213  /* the response header status */
214  RetVal = OutData.Status;
215  }
216  }
217  else
218  {
219  RetVal = Msg.Rsp.status;
220  }
221 
222  _SlDrvReleasePoolObj((_u8)ObjIdx);
223 
224  return RetVal;
225 }

§ 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 74 of file netutil.c.

75 {
76  SlNetUtilMsgGet_u Msg;
77  _SlCmdExt_t CmdExt;
78 
79  _SlDrvResetCmdExt(&CmdExt);
80  CmdExt.RxPayloadLen = *pValueLen;
81  CmdExt.pRxPayload = (_u8 *)pValues;
82 
83  Msg.Cmd.Option = Option;
84  Msg.Cmd.ObjId = ObjID;
85  Msg.Cmd.ValueLen = *pValueLen;
86 
87  VERIFY_RET_OK(_SlDrvCmdOp((_SlCmdCtrl_t *)&_SlNetUtilGetCmdCtrl, &Msg, &CmdExt));
88 
89  if(CmdExt.RxPayloadLen < CmdExt.ActualRxPayloadLen)
90  {
91  *pValueLen = CmdExt.RxPayloadLen;
92  return SL_ESMALLBUF;
93  }
94  else
95  {
96  *pValueLen = CmdExt.ActualRxPayloadLen;
97  }
98 
99  return (_i16)Msg.Rsp.Status;
100 }

§ 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

§ _SlNetUtilCmdData_t

struct _SlNetUtilCmdData_t

Definition at line 88 of file netutil.h.

Data Fields
_u16 * pOutputLen
_u8 * pOutputValues
_i16 Status

§ SlNetUtilCryptoEcCustomCurveParam_t

struct SlNetUtilCryptoEcCustomCurveParam_t

Definition at line 177 of file netutil.h.

Data Fields
_u8 Padding[4]

§ SlNetUtilCryptoEcCurveParams_u

union SlNetUtilCryptoEcCurveParams_u

Definition at line 184 of file netutil.h.

Data Fields
SlNetUtilCryptoEcCustomCurveParam_t CustomCurveParams
_u8 NamedCurveParams

§ SlNetUtilCryptoEcKeyParams_t

struct SlNetUtilCryptoEcKeyParams_t

Definition at line 202 of file netutil.h.

Data Fields
SlNetUtilCryptoEcCurveParams_u CurveParams
_u8 CurveType

§ SlNetUtilCryptoPubKeyParams_u

union SlNetUtilCryptoPubKeyParams_u

Definition at line 209 of file netutil.h.

Data Fields
SlNetUtilCryptoEcKeyParams_t EcParams

§ SlNetUtilCryptoPubKeyInfo_t

struct SlNetUtilCryptoPubKeyInfo_t

Definition at line 218 of file netutil.h.

Data Fields
_u8 CertFileNameLen
_u8 KeyAlgo
_u8 KeyFileNameLen
SlNetUtilCryptoPubKeyParams_u KeyParams

§ SlNetUtilCryptoCmdSignAttrib_t

struct SlNetUtilCryptoCmdSignAttrib_t

Definition at line 230 of file netutil.h.

Data Fields
_u32 Flags
_u32 ObjId
_u32 SigType

§ SlNetUtilCryptoCmdVerifyAttrib_t

struct SlNetUtilCryptoCmdVerifyAttrib_t

Definition at line 239 of file netutil.h.

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

§ SlNetUtilCryptoCmdCreateCertAttrib_t

struct SlNetUtilCryptoCmdCreateCertAttrib_t

Definition at line 249 of file netutil.h.

Data Fields
_u32 Flags
_u32 ObjId
_u16 SubCmd

§ SlNetUtilCryptoCmdKeyMgnt_t

struct SlNetUtilCryptoCmdKeyMgnt_t

Definition at line 258 of file netutil.h.

Data Fields
_u32 Flags
_u32 ObjId
_u16 SubCmd

§ NetUtilCmdArpLookupAttrib_t

struct NetUtilCmdArpLookupAttrib_t

Definition at line 266 of file netutil.h.

Data Fields
_u16 NumOfRetries
_u16 Timeout