Example #1
0
/*********************************************************************
 * @fn      SNP_addCharValueDec
 *
 * @brief   Add a characteristic value to a service table. Used after
 *          calling SNP_addService to include characteristics within the
 *          service.
 *
 * @param   pReq - pointer to SNP request message
 * @param   pReq - Length of UUID field in request message
 * @param   pRsp - pointer to SNP response message
 * 
 * @return  uint8_t - SNP_SUCCESS
 */
uint8_t SNP_addCharValueDec(snpAddCharValueDeclReq_t *pReq, uint8_t uuidLen,
                            snpAddCharValueDeclRsp_t *pRsp)
{
  _npiFrame_t *pPkt;
  uint16_t reqSize = sizeof(snpAddCharValueDeclReq_t) - sizeof(pReq->UUID);
  
  // Allocated an empty data NPI packet.
  pPkt = SNP_buildNPIPacket(SNP_NPI_SYNC_REQ_TYPE, 
                            SNP_ADD_CHAR_VAL_DECL_REQ, 
                            reqSize + uuidLen);
  
  
  // Copy non-pointer members of request struct
  pPkt->pData[0] = pReq->charValPerms;
  pPkt->pData[1] = LO_UINT16(pReq->charValProps);
  pPkt->pData[2] = HI_UINT16(pReq->charValProps);
  pPkt->pData[3] = pReq->mgmtOption;
  pPkt->pData[4] = LO_UINT16(pReq->charValMaxLen);
  pPkt->pData[5] = HI_UINT16(pReq->charValMaxLen);

  // Copy pointer members
  memcpy(&pPkt->pData[reqSize], pReq->UUID, uuidLen);
  
  // Send a synchronous command.
  SNP_sendSynchronousCmd(pPkt, SNP_ADD_CHAR_VAL_DECL_REQ, 
                          (snp_msg_t *)pRsp,NULL);
  
  // Return Status
  return SNP_SUCCESS;
}
/*********************************************************************
 * @fn      SNP_RPC_setWhiteListParam
 *
 * @brief   Set the White List policy.
 *
 * @param   pReq - pointer to SPN request message
 *
 * @return  uint8_t - SNP_SUCCESS
 */
uint8_t SNP_RPC_setWhiteListParam(snpSetWhiteListReq_t *pReq)
{
  snpSetWhiteListRsp_t rsp;
  _npiFrame_t *pPkt;
  uint8_t status = SNP_OUT_OF_RESOURCES;

  // Allocated an empty data NPI packet.
  pPkt = SNP_buildNPIPacket(SNP_NPI_SYNC_REQ_TYPE,
                            SNP_SET_WHITE_LIST_POLICY_REQ, 1);

  if ( pPkt )
  {
    status = SNP_SUCCESS;

    pPkt->pData[0] = pReq->useWhiteList;

    // Send a synchronous command.
    SNP_sendSynchronousCmd(pPkt, SNP_SET_WHITE_LIST_POLICY_REQ, (snp_msg_t *)&rsp,
                           NULL);

    status = rsp.status;
  }

  // Return Status
  return status;
}
/*********************************************************************
 * @fn      SNP_RPC_addService
 *
 * @brief   Add a service to the GATT server on the SNP.
 *
 * @param   pReq - pointer to SNP request message
 * @param   uuidLen - Length of UUID field in request message
 * @param   pRsp - pointer to SNP response message
 *
 * @return  uint8_t - SNP_SUCCESS
 */
uint8_t SNP_RPC_addService(snpAddServiceReq_t *pReq, uint8_t uuidLen,
                           snpAddServiceRsp_t *pRsp)
{
  _npiFrame_t *pPkt;
  uint8_t status = SNP_OUT_OF_RESOURCES;
  uint16_t reqSize = sizeof(snpAddServiceReq_t) - sizeof(pReq->UUID);

  // Allocated an empty data NPI packet.
  pPkt = SNP_buildNPIPacket(SNP_NPI_SYNC_REQ_TYPE, SNP_ADD_SERVICE_REQ,
                            reqSize + uuidLen);

  if ( pPkt )
  {
    status = SNP_SUCCESS;

    // Copy non-pointer members of request struct
    pPkt->pData[0] = pReq->type;

    // Copy pointer members
    memcpy(&pPkt->pData[reqSize],pReq->UUID, uuidLen);

    // Send a synchronous command.
    SNP_sendSynchronousCmd(pPkt, SNP_ADD_SERVICE_REQ, (snp_msg_t *)pRsp,NULL);
  }

  // Return Status
  return status;
}
/*********************************************************************
 * @fn      SNP_RPC_stAuthenticationData
 *
 * @brief   Set the Authentication data for a pairing procedure.
 *
 * @param   pReq - pointer to SPN request message
 *
 * @return  uint8_t - status of this command
 */
uint8_t SNP_RPC_setAuthenticationData(snpSetAuthDataReq_t *pReq)
{
  snpSetAuthDataRsp_t rsp;
  _npiFrame_t *pPkt;
  uint8_t *ptr;
  uint8_t status = SNP_OUT_OF_RESOURCES;

  // Allocated an empty data NPI packet.
  pPkt = SNP_buildNPIPacket(SNP_NPI_SYNC_REQ_TYPE,
                            SNP_SET_AUTHENTICATION_DATA_REQ, 4);

  if ( pPkt )
  {
    status = SNP_SUCCESS;

    ptr = pPkt->pData;
    UINT32_TO_BUF_LITTLE_ENDIAN(ptr, pReq->authData);

    // Send a synchronous command.
    SNP_sendSynchronousCmd(pPkt, SNP_SET_AUTHENTICATION_DATA_REQ,
                           (snp_msg_t *)&rsp, NULL);

    status = rsp.status;
  }

  // Return Status
  return status;
}
/*********************************************************************
 * @fn      SNP_RPC_setSecurityParam
 *
 * @brief   Set the Security Requirements for SNP.
 *
 * @param   pReq - pointer to SNP request message
 * @param   pRsp - pointer to SNP response message
 *
 * @return  uint8_t - SNP_SUCCESS
 */
uint8_t SNP_RPC_setSecurityParam(snpSetSecParamReq_t *pReq,
                                 snpSetSecParamRsp_t *pRsp)
{
  _npiFrame_t *pPkt;
  uint8_t status = SNP_OUT_OF_RESOURCES;

  // Allocated an empty data NPI packet.
  pPkt = SNP_buildNPIPacket(SNP_NPI_SYNC_REQ_TYPE, SNP_SET_SECURITY_PARAM_REQ,
                            sizeof(snpSetSecParamReq_t));

  if ( pPkt )
  {
    status = SNP_SUCCESS;

    pPkt->pData[0] = pReq->paramId;
    pPkt->pData[1] = pReq->value;

    // Send a synchronous command.
    SNP_sendSynchronousCmd(pPkt, SNP_SET_SECURITY_PARAM_REQ, (snp_msg_t *)pRsp,
                           NULL);
  }

  // Return Status
  return status;
}
/*********************************************************************
 * @fn      SNP_RPC_getGAPparam
 *
 * @brief   Get GAP parameter from SNP
 *
 * @param   pReq - pointer to SNP request message
 * @param   pRsp - pointer to SNP response message
 *
 * @return  uint8_t - SNP_SUCCESS
 */
uint8_t SNP_RPC_getGAPparam(snpGetGapParamReq_t *pReq,
                            snpGetGapParamRsp_t *pRsp)
{
  _npiFrame_t *pPkt;
  uint8_t status = SNP_OUT_OF_RESOURCES;

  // Allocated an empty data NPI packet.
  pPkt = SNP_buildNPIPacket(SNP_NPI_SYNC_REQ_TYPE, SNP_GET_GAP_PARAM_REQ,
                            sizeof(snpSetGapParamReq_t));

  if ( pPkt )
  {
    status = SNP_SUCCESS;

    // Copy non-pointer members of request struct
    pPkt->pData[0] = LO_UINT16(pReq->paramId);
    pPkt->pData[1] = HI_UINT16(pReq->paramId);
    pPkt->pData[2] = LO_UINT16(pReq->value);
    pPkt->pData[3] = HI_UINT16(pReq->value);

    // Send a synchronous command.
    SNP_sendSynchronousCmd(pPkt, SNP_ADD_SERVICE_REQ, (snp_msg_t *)pRsp,NULL);
  }

  // Return Status
  return status;
}
/*********************************************************************
 * @fn      SNP_RPC_maskEvent
 *
 * @brief   mask of events to to receive from the Network Processor
 *
 * @param   pReq - pointer to SNP request message
 * @param   pRsp - pointer to SNP response message
 *
 * @return  uint8_t - SNP_SUCCESS
 */
uint8_t SNP_RPC_maskEvent(snpMaskEventReq_t *pReq,
                          snpMaskEventRsp_t *pRsp)
{
  _npiFrame_t *pPkt;
  uint8_t status = SNP_OUT_OF_RESOURCES;

  // Allocated an empty data NPI packet.
  pPkt = SNP_buildNPIPacket(SNP_NPI_SYNC_REQ_TYPE , SNP_MASK_EVT_REQ,
                            sizeof(snpMaskEventReq_t));

  if ( pPkt )
  {
    status = SNP_SUCCESS;

    // Initialize Request packet
    pPkt->pData[0] = LO_UINT16(pReq->eventMask);
    pPkt->pData[1] = HI_UINT16(pReq->eventMask);

    // Send a synchronous command.
    SNP_sendSynchronousCmd(pPkt, SNP_MASK_EVT_REQ, (snp_msg_t *)pRsp,NULL);
  }

  // Return Status
  return status;
}
Example #8
0
/*********************************************************************
 * @fn      SNP_getStatus
 *
 * @brief   Get SNP status
 *
 * @param   pRsp - pointer to SNP response message
 *
 * @return  uint8_t - SNP_SUCCESS
 */
uint8_t SNP_getStatus(snpGetStatusCmdRsp_t *pRsp)
{
  _npiFrame_t *pPkt;

  // Allocated an empty data NPI packet.
  pPkt = SNP_buildNPIPacket(SNP_NPI_SYNC_REQ_TYPE, 
                             SNP_GET_STATUS_REQ, 0);
  
  // Send a synchronous command.
  SNP_sendSynchronousCmd(pPkt, SNP_GET_STATUS_REQ, 
                          (snp_msg_t *)pRsp, NULL);
  
  // Return Status
  return SNP_SUCCESS;  
}
/*********************************************************************
 * @fn      SNP_RPC_getRand
 *
 * @brief   Get random number generated using TRNG on SNP
 *
 * @param   pRsp - pointer to SNP response message
 *
 * @return  uint8_t - SNP_SUCCESS
 */
uint8_t SNP_RPC_getRand(snpGetRandRsp_t *pRsp)
{
  _npiFrame_t *pPkt;
  uint8_t status = SNP_OUT_OF_RESOURCES;

  // Allocated an empty data NPI packet.
  pPkt = SNP_buildNPIPacket(SNP_NPI_SYNC_REQ_TYPE, SNP_GET_RAND_REQ, 0);

  if ( pPkt )
  {
    status = SNP_SUCCESS;

    // Send a synchronous command.
    SNP_sendSynchronousCmd(pPkt, SNP_GET_RAND_REQ, (snp_msg_t *)pRsp, NULL);
  }

  // Return Status
  return status;
}
/*********************************************************************
 * @fn      SNP_RPC_addCharDescDec
 *
 * @brief   Add a characteristic user description, CCCD, format attribute
 *          to a characteristic on SNP.
 *
 * @param   pReq - pointer to SNP request message
 * @param   pReq - Length of UUID field in request message
 * @param   pRsp - pointer to SNP response message
 *
 * @return  uint8_t - SNP_SUCCESS
 */
uint8_t SNP_RPC_addCharDescDec(snpAddCharDescDeclReq_t *pReq,
                               snpAddCharDescDeclRsp_t *pRsp)
{
  _npiFrame_t *pPkt;
  uint8_t status = SNP_OUT_OF_RESOURCES;
  uint16_t pktLen = 0;
  uint16_t pktIdx = 0;

  // Verify only sending supported Attributes
  if (pReq->header & SNP_DESC_HEADER_UNSUPPORTED_MASK)
  {
    return SNP_FAILURE;
  }

  // Determine Size of Packet
  pktLen += sizeof(pReq->header);
  pktLen += (pReq->header & SNP_DESC_HEADER_GEN_SHORT_UUID) ?
            sizeof(snpAddAttrGenShortUUID_t) : 0;
  pktLen += (pReq->header & SNP_DESC_HEADER_GEN_LONG_UUID) ?
            sizeof(snpAddAttrGenLongUUID_t) : 0;
  pktLen += (pReq->header & SNP_DESC_HEADER_CCCD) ?
            sizeof(snpAddAttrCccd_t) : 0;
  pktLen += (pReq->header & SNP_DESC_HEADER_FORMAT) ?
            sizeof(snpAddAttrFormat_t) : 0;
  pktLen += (pReq->header & SNP_DESC_HEADER_USER_DESC) ?
            sizeof(snpAddAttrUserDesc_t) - sizeof(pReq->pUserDesc->pDesc) +
            pReq->pUserDesc->initLen : 0;

  // Allocated an empty data NPI packet.
  pPkt = SNP_buildNPIPacket(SNP_NPI_SYNC_REQ_TYPE, SNP_ADD_CHAR_DESC_DECL_REQ,
                            pktLen);

  if ( pPkt )
  {
    status = SNP_SUCCESS;
    // Copy statically sized members of struct
    pPkt->pData[pktIdx++] = pReq->header;

    // Short UUID
    if (pReq->header & SNP_DESC_HEADER_GEN_SHORT_UUID)
    {
      pPkt->pData[pktIdx++] = pReq->pShortUUID->perms;
      pPkt->pData[pktIdx++] = LO_UINT16(pReq->pShortUUID->maxLen);
      pPkt->pData[pktIdx++] = HI_UINT16(pReq->pShortUUID->maxLen);
      pPkt->pData[pktIdx++] = pReq->pShortUUID->UUID[0];
      pPkt->pData[pktIdx++] = pReq->pShortUUID->UUID[1];
    }

    // Long UUID
    if (pReq->header & SNP_DESC_HEADER_GEN_LONG_UUID)
    {
      pPkt->pData[pktIdx++] = pReq->pLongUUID->perms;
      pPkt->pData[pktIdx++] = LO_UINT16(pReq->pLongUUID->maxLen);
      pPkt->pData[pktIdx++] = HI_UINT16(pReq->pLongUUID->maxLen);

      memcpy(&pPkt->pData[pktIdx],pReq->pLongUUID->UUID,
             sizeof(pReq->pLongUUID->UUID));
      pktIdx += sizeof(pReq->pLongUUID->UUID);
    }

    // CCCD
    if (pReq->header & SNP_DESC_HEADER_CCCD)
    {
      // Copy statically sized members of struct
      pPkt->pData[pktIdx++] = pReq->pCCCD->perms;
    }

    // Format
    if (pReq->header & SNP_DESC_HEADER_FORMAT)
    {
      // Copy statically sized members of struct
      pPkt->pData[pktIdx++] = pReq->pFormat->format;
      pPkt->pData[pktIdx++] = pReq->pFormat->exponent;
      pPkt->pData[pktIdx++] = LO_UINT16(pReq->pFormat->unit);
      pPkt->pData[pktIdx++] = HI_UINT16(pReq->pFormat->unit);
      pPkt->pData[pktIdx++] = pReq->pFormat->namespace;
      pPkt->pData[pktIdx++] = LO_UINT16(pReq->pFormat->desc);
      pPkt->pData[pktIdx++] = HI_UINT16(pReq->pFormat->desc);
    }

    // User Desc
    if (pReq->header & SNP_DESC_HEADER_USER_DESC)
    {
      // Copy statically sized members of struct
      pPkt->pData[pktIdx++] = pReq->pUserDesc->perms;
      pPkt->pData[pktIdx++] = LO_UINT16(pReq->pUserDesc->maxLen);
      pPkt->pData[pktIdx++] = HI_UINT16(pReq->pUserDesc->maxLen);
      pPkt->pData[pktIdx++] = LO_UINT16(pReq->pUserDesc->initLen);
      pPkt->pData[pktIdx++] = HI_UINT16(pReq->pUserDesc->initLen);

      // Copy dynamic sized members of struct
      memcpy(&pPkt->pData[pktIdx],pReq->pUserDesc->pDesc,
             pReq->pUserDesc->initLen);
      pktIdx += pReq->pUserDesc->initLen;
    }

    // Send a synchronous command.
    SNP_sendSynchronousCmd(pPkt, SNP_ADD_CHAR_DESC_DECL_REQ, (snp_msg_t *)pRsp,
                           NULL);
  }