123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449 |
- #include "hal_mcu.h"
- #include "hal_board.h"
- #include "mac_api.h"
- #include "mac_spec.h"
- #include "mac_low_level.h"
- #include "mac_radio_defs.h"
- #include "mac_main.h"
- #include "mac_pib.h"
- #include "OSAL.h"
- #include <stddef.h>
- #define MAC_ATTR_SET1_START 0x40
- #define MAC_ATTR_SET1_END 0x5D
- #define MAC_ATTR_SET1_OFFSET 0
- #define MAC_ATTR_SET2_START 0xE0
- #define MAC_ATTR_SET2_END 0xE5
- #define MAC_ATTR_SET2_OFFSET (MAC_ATTR_SET1_END - MAC_ATTR_SET1_START + MAC_ATTR_SET1_OFFSET + 1)
- #define MAC_MAX_FRAME_RESPONSE_MIN 143
- #define MAC_MAX_FRAME_RESPONSE_MAX 25776
- typedef struct
- {
- uint8 offset;
- uint8 len;
- uint8 min;
- uint8 max;
- } macPibTbl_t;
- static CODE const macPib_t macPibDefaults =
- {
- 54,
- FALSE,
- TRUE,
- FALSE,
- 6,
- NULL,
- 0,
- MAC_BO_NON_BEACON,
- 0,
- 0,
- {0, SADDR_MODE_EXT},
- MAC_SHORT_ADDR_NONE,
- 0,
- FALSE,
- 4,
- 3,
- 0xFFFF,
- FALSE,
- FALSE,
- MAC_SHORT_ADDR_NONE,
- MAC_SO_NONE,
- 0x01F4,
- FALSE,
- 5,
- 1220,
- 3,
- 32,
- 0,
- TRUE,
- FALSE,
-
- #if defined (HAL_PA_LNA)
- 19,
- #elif defined (HAL_PA_LNA_CC2590)
- 11,
- #else
- 3,
- #endif
- MAC_CHAN_11,
- {0, SADDR_MODE_EXT},
- 1,
- MAC_BO_NON_BEACON,
- };
- static CODE const macPibTbl_t macPibTbl[] =
- {
- {offsetof(macPib_t, ackWaitDuration), sizeof(uint8), 54, 54},
- {offsetof(macPib_t, associationPermit), sizeof(bool), FALSE, TRUE},
- {offsetof(macPib_t, autoRequest), sizeof(bool), FALSE, TRUE},
- {offsetof(macPib_t, battLifeExt), sizeof(bool), FALSE, TRUE},
- {offsetof(macPib_t, battLifeExtPeriods), sizeof(uint8), 6, 6},
- {offsetof(macPib_t, pBeaconPayload), sizeof(uint8 *), 0, 0},
- {offsetof(macPib_t, beaconPayloadLength), sizeof(uint8), 0, 52},
- {offsetof(macPib_t, beaconOrder), sizeof(uint8), 0, 15},
- {offsetof(macPib_t, beaconTxTime), sizeof(uint32), 1, 1},
- {offsetof(macPib_t, bsn), sizeof(uint8), 0x00, 0xFF},
- {offsetof(macPib_t, coordExtendedAddress.addr.extAddr), sizeof(sAddrExt_t), 0, 0},
- {offsetof(macPib_t, coordShortAddress), sizeof(uint16), 0, 0},
- {offsetof(macPib_t, dsn), sizeof(uint8), 0x00, 0xFF},
- {offsetof(macPib_t, gtsPermit), sizeof(bool), FALSE, TRUE},
-
- {offsetof(macPib_t, maxCsmaBackoffs), sizeof(uint8), 0, 254},
- {offsetof(macPib_t, minBe), sizeof(uint8), 0, 8},
- {offsetof(macPib_t, panId), sizeof(uint16), 0, 0},
- {offsetof(macPib_t, promiscuousMode), sizeof(bool), FALSE, TRUE},
- {offsetof(macPib_t, rxOnWhenIdle), sizeof(bool), FALSE, TRUE},
- {offsetof(macPib_t, shortAddress), sizeof(uint16), 0, 0},
- {offsetof(macPib_t, superframeOrder), sizeof(uint8), 0, 15},
- {offsetof(macPib_t, transactionPersistenceTime), sizeof(uint16), 0, 0},
- {offsetof(macPib_t, associatedPanCoord), sizeof(bool), FALSE, TRUE},
-
- {offsetof(macPib_t, maxBe), sizeof(uint8), 0, 8},
- {offsetof(macPib_t, maxFrameTotalWaitTime), sizeof(uint16), 0x00, 0xFF},
- {offsetof(macPib_t, maxFrameRetries), sizeof(uint8), 0, 7},
- {offsetof(macPib_t, responseWaitTime), sizeof(uint8), 2, 64},
- {offsetof(macPib_t, syncSymbolOffset), sizeof(uint8), 0, 0},
- {offsetof(macPib_t, timeStampSupported), sizeof(bool), FALSE, TRUE},
- {offsetof(macPib_t, securityEnabled), sizeof(bool), FALSE, TRUE},
-
- {offsetof(macPib_t, phyTransmitPower), sizeof(uint8), 0, 0xFF},
- {offsetof(macPib_t, logicalChannel), sizeof(uint8), MAC_CHAN_11, MAC_CHAN_28},
- {offsetof(macPib_t, extendedAddress.addr.extAddr), sizeof(sAddrExt_t), 0, 0},
- {offsetof(macPib_t, altBe), sizeof(uint8), 0, 8},
- {offsetof(macPib_t, deviceBeaconOrder), sizeof(uint8), 0, 15},
- {offsetof(macPib_t, phyTransmitPower), sizeof(uint8), 0, 0},
- };
- #define MAC_PIB_INVALID ((uint8) (sizeof(macPibTbl) / sizeof(macPibTbl[0])))
- macPib_t macPib;
- MAC_INTERNAL_API void macPibReset(void)
- {
-
- macPib = macPibDefaults;
-
- macPib.dsn = macRadioRandomByte();
- macPib.bsn = macRadioRandomByte();
- }
- static uint8 macPibIndex(uint8 pibAttribute)
- {
- if ((pibAttribute >= MAC_ATTR_SET1_START) && (pibAttribute <= MAC_ATTR_SET1_END))
- {
- return (pibAttribute - MAC_ATTR_SET1_START + MAC_ATTR_SET1_OFFSET);
- }
- else if ((pibAttribute >= MAC_ATTR_SET2_START) && (pibAttribute <= MAC_ATTR_SET2_END))
- {
- return (pibAttribute - MAC_ATTR_SET2_START + MAC_ATTR_SET2_OFFSET);
- }
- else
- {
- return MAC_PIB_INVALID;
- }
- }
- 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;
- }
- uint8 MAC_MlmeSetReq(uint8 pibAttribute, void *pValue)
- {
- uint8 i;
- halIntState_t intState;
- if (pibAttribute == MAC_BEACON_PAYLOAD)
- {
- macPib.pBeaconPayload = pValue;
- return MAC_SUCCESS;
- }
-
- if ((i = macPibIndex(pibAttribute)) == MAC_PIB_INVALID)
- {
- return MAC_UNSUPPORTED_ATTRIBUTE;
- }
-
- if ((macPibTbl[i].min != 0) || (macPibTbl[i].max != 0))
- {
-
- if (macPibTbl[i].min == macPibTbl[i].max)
- {
- return MAC_READ_ONLY;
- }
-
- 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;
- }
- }
-
- if ((*((uint8 *) pValue) < macPibTbl[i].min) || (*((uint8 *) pValue) > macPibTbl[i].max))
- {
- return MAC_INVALID_PARAMETER;
- }
- }
-
- HAL_ENTER_CRITICAL_SECTION(intState);
- osal_memcpy((uint8 *) &macPib + macPibTbl[i].offset, pValue, macPibTbl[i].len);
- HAL_EXIT_CRITICAL_SECTION(intState);
-
- switch (pibAttribute)
- {
- case MAC_PAN_ID:
-
- macRadioSetPanID(macPib.panId);
- break;
- case MAC_SHORT_ADDRESS:
-
- macRadioSetShortAddr(macPib.shortAddress);
- break;
- case MAC_RX_ON_WHEN_IDLE:
-
- 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:
-
- macRadioSetIEEEAddr(macPib.extendedAddress.addr.extAddr);
- break;
- #ifndef MAC_OBSOLETE_PHY_TRANSMIT_POWER
-
- case MAC_PHY_TRANSMIT_POWER:
-
- #if !defined HAL_MAC_USE_REGISTER_POWER_VALUES && \
- !defined HAL_PA_LNA && !defined HAL_PA_LNA_CC2590
-
- macPib.phyTransmitPower = (uint8)(-(int8)macPib.phyTransmitPower);
- #endif
-
- #endif
- case MAC_PHY_TRANSMIT_POWER_SIGNED:
- (void)macRadioSetTxPower(macPib.phyTransmitPower);
- break;
- default:
- break;
- }
- return MAC_SUCCESS;
- }
|