Exemplo n.º 1
0
/********************************************************************************************************
 * @fn      ZMacSendNoData
 *
 * @brief   This function sends an empty msg
 *
 * @param   DstAddr   - destination short address
 *          DstPANId  - destination pan id
 *
 * @return  None
 ********************************************************************************************************/
void ZMacSendNoData ( uint16 DstAddr, uint16 DstPANId )
{
  macMcpsDataReq_t *pBuf;

  /* Allocate memory */
  pBuf = MAC_McpsDataAlloc(0, MAC_SEC_LEVEL_NONE, MAC_KEY_ID_MODE_NONE);

  if (pBuf)
  {
    /* Fill in src information */
    pBuf->mac.srcAddrMode              = SADDR_MODE_SHORT;

    /* Fill in dst information */
    pBuf->mac.dstAddr.addr.shortAddr   = DstAddr;
    pBuf->mac.dstAddr.addrMode         = SADDR_MODE_SHORT;
    pBuf->mac.dstPanId                 = DstPANId;

    /* Misc information */
    pBuf->mac.msduHandle               = 0;
    pBuf->mac.txOptions                = ZMAC_TXOPTION_ACK | ZMAC_TXOPTION_NO_RETRANS | ZMAC_TXOPTION_NO_CNF;

    /* Right now, set security to zero */
    pBuf->sec.securityLevel = false;

    /* Call Mac Data Request */
    MAC_McpsDataReq(pBuf);
  }

}
Exemplo n.º 2
0
/********************************************************************************************************
 * @fn      ZMacDataReq
 *
 * @brief   Send a MAC Data Frame packet.
 *
 * @param   structure containing data and where to send it.
 *
 * @return  status
 ********************************************************************************************************/
ROOT uint8 ZMacDataReq( ZMacDataReq_t *pData )
{
  macMcpsDataReq_t *pBuf;

  /* Allocate memory */
  pBuf = MAC_McpsDataAlloc(pData->msduLength, MAC_SEC_LEVEL_NONE, MAC_KEY_ID_MODE_NONE);

  if (pBuf)
  {
    /* Copy the addresses */
    osal_memcpy (&pBuf->mac, pData, sizeof (macDataReq_t));

    /* Copy data */
    pBuf->msdu.len = pData->msduLength;
    osal_memcpy (pBuf->msdu.p, pData->msdu, pData->msduLength);

    /* Right now, set security to zero */
    pBuf->sec.securityLevel = false;

    /* Call Mac Data Request */
    MAC_McpsDataReq(pBuf);

    return ( ZMacSuccess );
  }

  return MAC_NO_RESOURCES;
}
Exemplo n.º 3
0
/********************************************************************************************************
 * @fn      ZMacDataReqSec
 *
 * @brief   Send a MAC Data Frame packet, calls the passed in function to apply non-MAC security
 *          on the MAC data field after the MAC buffer allocation.
 *
 * @param   pData - structure containing data and where to send it.
 * @param   secCB - callback function to apply security, NULL indicates no security
 *
 * @return  status
 ********************************************************************************************************/
uint8 ZMacDataReqSec( ZMacDataReq_t *pData, applySecCB_t secCB )
{
  macMcpsDataReq_t *pBuf;

  /* Allocate memory */
  pBuf = MAC_McpsDataAlloc( pData->msduLength, MAC_SEC_LEVEL_NONE, MAC_KEY_ID_MODE_NONE );

  if ( pBuf )
  {
    /* Copy the addresses */
    osal_memcpy( &pBuf->mac, pData, sizeof (macDataReq_t) );

    /* Copy data */
    pBuf->msdu.len = pData->msduLength;
    osal_memcpy( pBuf->msdu.p, pData->msdu, pData->msduLength );
    
    /* Encrypt in place */
    if ( secCB && pBuf->msdu.len && pBuf->msdu.p )
    {
      if ( secCB( pBuf->msdu.len, pBuf->msdu.p ) != ZSuccess )
      {
        // Deallocate the buffer.  MAC_McpsDataAlloc() calls osal_msg_allocate() and
        // returns the same pointer.
        osal_msg_deallocate( (uint8 *)pBuf );
        
        return ( MAC_NO_RESOURCES );
      }
    }

    /* Right now, set MAC security to off */
    pBuf->sec.securityLevel = false;

    /* Call Mac Data Request */
    MAC_McpsDataReq( pBuf );

    return ( ZMacSuccess );
  }

  return ( MAC_NO_RESOURCES );
}
Exemplo n.º 4
0
/********************************************************************************************************
 * @fn      ZMacDataReqSec
 *
 * @brief   Send a MAC Data Frame packet, calls the passed in function to apply non-MAC security
 *          on the MAC data field after the MAC buffer allocation.
 *
 * @param   pData - structure containing data and where to send it.
 * @param   secCB - callback function to apply security, NULL indicates no security
 *
 * @return  status
 ********************************************************************************************************/
uint8 ZMacDataReqSec( ZMacDataReq_t *pData, applySecCB_t secCB )
{
  macMcpsDataReq_t *pBuf;

  /* Allocate memory */
  pBuf = MAC_McpsDataAlloc( pData->msduLength, pData->Sec.SecurityLevel, pData->Sec.KeyIdMode );

  if ( pBuf )
  {
    /* Copy the addresses */
    osal_memcpy( &pBuf->mac, pData, sizeof (macDataReq_t) );

    /* Copy data */
    osal_memcpy( pBuf->msdu.p, pData->msdu, pData->msduLength );

    /* Copy Security parameters */
    osal_memcpy( &pBuf->sec, &pData->Sec, sizeof (macSec_t));

    /* Encrypt in place */
    if ( secCB && pBuf->msdu.len && pBuf->msdu.p )
    {
      if ( secCB( pBuf->msdu.len, pBuf->msdu.p ) != ZSuccess )
      {
        // Deallocate the buffer.  MAC_McpsDataAlloc() calls osal_msg_allocate() and
        // returns the same pointer.
        osal_msg_deallocate( (uint8 *)pBuf );

        return ( MAC_NO_RESOURCES );
      }
    }

    /* Call Mac Data Request */
    MAC_McpsDataReq( pBuf );

    return ( ZMacSuccess );
  }

  return ( MAC_NO_RESOURCES );
}