Пример #1
0
/**************************************************************************************************
 * @fn          MAC_MlmeGetReqSize
 *
 * @brief       This direct execute function gets the MAC PIB attribute size
 *
 * input parameters
 *
 * @param       pibAttribute - The attribute identifier.
 *
 * output parameters
 *
 * None.
 *
 * @return      size in bytes
 *
 **************************************************************************************************
 */
uint8 MAC_MlmeGetReqSize( uint8 pibAttribute )
{
    uint8 index;

    if ((index = macPibIndex(pibAttribute)) == MAC_PIB_INVALID)
    {
        return 0;
    }

    return ( macPibTbl[index].len );
}
Пример #2
0
/**************************************************************************************************
 * @fn          MAC_MlmeGetReq
 *
 * @brief       This direct execute function retrieves an attribute value
 *              from the MAC PIB.
 *
 * input parameters
 *
 * @param       pibAttribute - The attribute identifier.
 * @param       pValue - pointer to the attribute value.
 *
 * output parameters
 *
 * @param       pValue - pointer to the attribute value.
 *
 * @return      The status of the request, as follows:
 *              MAC_SUCCESS Operation successful.
 *              MAC_UNSUPPORTED_ATTRIBUTE Attribute not found.
 *
 **************************************************************************************************
 */
uint8 MAC_MlmeGetReq(uint8 pibAttribute, void *pValue)
{
  uint8         i;
  halIntState_t intState;

  if ((i = macPibIndex(pibAttribute)) == MAC_PIB_INVALID)
  {
    return MAC_UNSUPPORTED_ATTRIBUTE;
  }

  HAL_ENTER_CRITICAL_SECTION(intState);
  osal_memcpy(pValue, (uint8 *) &macPib + macPibTbl[i].offset, macPibTbl[i].len);
  HAL_EXIT_CRITICAL_SECTION(intState);
  return MAC_SUCCESS;
}
Пример #3
0
/**************************************************************************************************
 * @fn          MAC_MlmeSetReq
 *
 * @brief       This direct execute function sets an attribute value
 *              in the MAC PIB.
 *
 * input parameters
 *
 * @param       pibAttribute - The attribute identifier.
 * @param       pValue - pointer to the attribute value.
 *
 * output parameters
 *
 * None.
 *
 * @return      The status of the request, as follows:
 *              MAC_SUCCESS Operation successful.
 *              MAC_UNSUPPORTED_ATTRIBUTE Attribute not found.
 *
 **************************************************************************************************
 */
uint8 MAC_MlmeSetReq(uint8 pibAttribute, void *pValue)
{
  uint8         i;
  halIntState_t intState;

  if (pibAttribute == MAC_BEACON_PAYLOAD)
  {
    macPib.pBeaconPayload = pValue;
    return MAC_SUCCESS;
  }

  /* look up attribute in PIB table */
  if ((i = macPibIndex(pibAttribute)) == MAC_PIB_INVALID)
  {
    return MAC_UNSUPPORTED_ATTRIBUTE;
  }

  /* do range check; no range check if min and max are zero */
  if ((macPibTbl[i].min != 0) || (macPibTbl[i].max != 0))
  {
    /* if min == max, this is a read-only attribute */
    if (macPibTbl[i].min == macPibTbl[i].max)
    {
      return MAC_READ_ONLY;
    }

    /* check for special cases */
    if (pibAttribute == MAC_MAX_FRAME_TOTAL_WAIT_TIME)
    {
      if ((*((uint16 *) pValue) < MAC_MAX_FRAME_RESPONSE_MIN) ||
          (*((uint16 *) pValue) > MAC_MAX_FRAME_RESPONSE_MAX))
      {
        return MAC_INVALID_PARAMETER;
      }
    }

    /* range check for general case */
    if ((*((uint8 *) pValue) < macPibTbl[i].min) || (*((uint8 *) pValue) > macPibTbl[i].max))
    {
      return MAC_INVALID_PARAMETER;
    }

  }

  /* set value in PIB */
  HAL_ENTER_CRITICAL_SECTION(intState);
  osal_memcpy((uint8 *) &macPib + macPibTbl[i].offset, pValue, macPibTbl[i].len);
  HAL_EXIT_CRITICAL_SECTION(intState);

  /* handle special cases */
  switch (pibAttribute)
  {
    case MAC_PAN_ID:
      /* set pan id in radio */
      macRadioSetPanID(macPib.panId);
      break;

    case MAC_SHORT_ADDRESS:
      /* set short address in radio */
      macRadioSetShortAddr(macPib.shortAddress);
      break;

    case MAC_RX_ON_WHEN_IDLE:
      /* turn rx on or off */
      if (macPib.rxOnWhenIdle)
      {
        macRxEnable(MAC_RX_WHEN_IDLE);
      }
      else
      {
        macRxDisable(MAC_RX_WHEN_IDLE);
      }
      break;

    case MAC_LOGICAL_CHANNEL:
      macRadioSetChannel(macPib.logicalChannel);
      break;

    case MAC_EXTENDED_ADDRESS:
      /* set ext address in radio */
      macRadioSetIEEEAddr(macPib.extendedAddress.addr.extAddr);
      break;

#ifndef MAC_OBSOLETE_PHY_TRANSMIT_POWER
    /* Define MAC_OBSOLETE_PHY_TRANSMIT_POWER to save some code */

    case MAC_PHY_TRANSMIT_POWER:
      /* Legacy transmit power attribute */
#if !defined HAL_MAC_USE_REGISTER_POWER_VALUES && \
  !defined HAL_PA_LNA && !defined HAL_PA_LNA_CC2590
      /* Legacy transmit power attribute value for CC2530 alone,
       * or runtime selection support build means a negative absolute value.
       * However, when used as register power values or
       * with HAL_PA_LNAxxx definition (without runtime selection)
       * the attribute value is not a negative absolute value. */
      macPib.phyTransmitPower = (uint8)(-(int8)macPib.phyTransmitPower);
#endif /* !defined HAL_MAC_USE_REGISTER_POWER_VALUES && ... */
      /* pass through to next case -- do not break*/

#endif /* MAC_OBSOLETE_PHY_TRANSMIT_POWER */

    case MAC_PHY_TRANSMIT_POWER_SIGNED:
      (void)macRadioSetTxPower(macPib.phyTransmitPower);
      break;

    default:
      break;
  }

  return MAC_SUCCESS;
}
Пример #4
0
/**************************************************************************************************
 * @fn          MAC_MlmeSetReq
 *
 * @brief       This direct execute function sets an attribute value
 *              in the MAC PIB.
 *
 * input parameters
 *
 * @param       pibAttribute - The attribute identifier.
 * @param       pValue - pointer to the attribute value.
 *
 * output parameters
 *
 * None.
 *
 * @return      The status of the request, as follows:
 *              MAC_SUCCESS Operation successful.
 *              MAC_UNSUPPORTED_ATTRIBUTE Attribute not found.
 *
 **************************************************************************************************
 */
uint8 MAC_MlmeSetReq(uint8 pibAttribute, void *pValue)
{
    uint8         i;
    halIntState_t intState;

    if (pibAttribute == MAC_BEACON_PAYLOAD)
    {
        macPib.pBeaconPayload = pValue;
        return MAC_SUCCESS;
    }

    /* look up attribute in PIB table */
    if ((i = macPibIndex(pibAttribute)) == MAC_PIB_INVALID)
    {
        return MAC_UNSUPPORTED_ATTRIBUTE;
    }

    /* do range check; no range check if min and max are zero */
    if ((macPibTbl[i].min != 0) || (macPibTbl[i].max != 0))
    {
        /* if min == max, this is a read-only attribute */
        if (macPibTbl[i].min == macPibTbl[i].max)
        {
            return MAC_READ_ONLY;
        }

        /* check for special cases */
        if (pibAttribute == MAC_MAX_FRAME_TOTAL_WAIT_TIME)
        {
            if ((*((uint16 *) pValue) < MAC_MAX_FRAME_RESPONSE_MIN) ||
                    (*((uint16 *) pValue) > MAC_MAX_FRAME_RESPONSE_MAX))
            {
                return MAC_INVALID_PARAMETER;
            }
        }

        /* range check for general case */
        if ((*((uint8 *) pValue) < macPibTbl[i].min) || (*((uint8 *) pValue) > macPibTbl[i].max))
        {
            return MAC_INVALID_PARAMETER;
        }

    }

    /* set value in PIB */
    HAL_ENTER_CRITICAL_SECTION(intState);
    osal_memcpy((uint8 *) &macPib + macPibTbl[i].offset, pValue, macPibTbl[i].len);
    HAL_EXIT_CRITICAL_SECTION(intState);

    /* handle special cases */
    switch (pibAttribute)
    {
    case MAC_PAN_ID:
        /* set pan id in radio */
        macRadioSetPanID(macPib.panId);
        break;

    case MAC_SHORT_ADDRESS:
        /* set short address in radio */
        macRadioSetShortAddr(macPib.shortAddress);
        break;

    case MAC_RX_ON_WHEN_IDLE:
        /* turn rx on or off */
        if (macPib.rxOnWhenIdle)
        {
            macRxEnable(MAC_RX_WHEN_IDLE);
        }
        else
        {
            macRxDisable(MAC_RX_WHEN_IDLE);
        }
        break;

    case MAC_LOGICAL_CHANNEL:
        macRadioSetChannel(macPib.logicalChannel);
        break;

    case MAC_EXTENDED_ADDRESS:
        /* set ext address in radio */
        macRadioSetIEEEAddr(macPib.extendedAddress.addr.extAddr);
        break;

    case MAC_PHY_TRANSMIT_POWER_SIGNED:
        (void)macRadioSetTxPower(macPib.phyTransmitPower);
        break;

    case MAC_RF4CE_POWER_SAVINGS:
        macPib.rf4cepowerSavings = *(uint8 *)pValue;
        break;

    default:
        break;
    }

    return MAC_SUCCESS;
}