static int req_start(uint8_t chan, bool coord) /* this function configures the coordinator. * NOTE: when in periodic mode, active scan will NOT be answered immediatly. */ { void *mac = pvAppApiGetMacHandle(); MAC_Pib_s *pib = MAC_psPibGetHandle(mac); MAC_MlmeReqRsp_s mlmereq; MAC_MlmeSyncCfm_s mlmecfm; memcpy(&pib->sCoordExtAddr, pvAppApiGetMacAddrLocation(), sizeof(MAC_ExtAddr_s)); mlmereq.u8Type = MAC_MLME_REQ_START; mlmereq.u8ParamLength = sizeof(MAC_MlmeReqScan_s); mlmereq.uParam.sReqStart.u16PanId = 0xbeef; mlmereq.uParam.sReqStart.u8Channel = chan; mlmereq.uParam.sReqStart.u8BeaconOrder = 15; mlmereq.uParam.sReqStart.u8SuperframeOrder = 15; mlmereq.uParam.sReqStart.u8PanCoordinator = coord; mlmereq.uParam.sReqStart.u8BatteryLifeExt = false; mlmereq.uParam.sReqStart.u8Realignment = false; mlmereq.uParam.sReqStart.u8SecurityEnable = false; vAppApiMlmeRequest(&mlmereq, &mlmecfm); return mlmecfm.uParam.sCfmStart.u8Status; }
uint32_t IEEE802154::init(uint16_t panid) { IEEE802154_DBG_FUNC_ENTER(); void *pvMac; uint32_t version; version = u32AppApiInit(MlmeDcfmIndGetBuf, MlmeDcfmIndPost, this, McpsDcfmIndGetBuf, McpsDcfmIndPost, this); IEEE802154_DBG_PRINTLN("pvAppApiGetMacHandle"); pvMac = pvAppApiGetMacHandle(); IEEE802154_DBG_PRINTLN("MAC_psPibGetHandle"); (void)MAC_psPibGetHandle(pvMac); IEEE802154_DBG_PRINTF("MAC_vPibSetPanId: 0x%x", panid); IEEE802154_DBG_PRINTLN(""); MAC_vPibSetPanId(pvMac, panid); /* Enable receiver to be on when idle */ IEEE802154_DBG_PRINTLN("MAC_vPibSetRxOnWhenIdle"); MAC_vPibSetRxOnWhenIdle(pvMac, 1, FALSE); return version; }
static void req_start(uint8 chan, bool coord) /* this function configures the coordinator. * NOTE: when in periodic mode, active scan will NOT be answered immediatly. */ { void *mac = pvAppApiGetMacHandle(); MAC_Pib_s *pib = MAC_psPibGetHandle(mac); MAC_MlmeReqRsp_s mlmereq; MAC_MlmeSyncCfm_s mlmecfm; MAC_vPibSetShortAddr(mac, 0x0000); pib->bAssociationPermit = true; memcpy(&pib->sCoordExtAddr, ieee_get_mac(), sizeof(MAC_ExtAddr_s)); mlmereq.u8Type = MAC_MLME_REQ_START; mlmereq.u8ParamLength = sizeof(MAC_MlmeReqScan_s); mlmereq.uParam.sReqStart.u16PanId = IEEE802154_PANDID; mlmereq.uParam.sReqStart.u8Channel = chan; mlmereq.uParam.sReqStart.u8BeaconOrder = BEACON_ORDER; mlmereq.uParam.sReqStart.u8SuperframeOrder = SUPERFRAME_ORDER; mlmereq.uParam.sReqStart.u8PanCoordinator = coord; mlmereq.uParam.sReqStart.u8BatteryLifeExt = false; mlmereq.uParam.sReqStart.u8Realignment = false; mlmereq.uParam.sReqStart.u8SecurityEnable = false; vAppApiMlmeRequest(&mlmereq, &mlmecfm); }
/**************************************************************************** * * NAME: NODE_vInit * * DESCRIPTION: * Initialises Zigbee stack, hardware and application. * ****************************************************************************/ PUBLIC void NODE_vInit(void) { uint32 u32RandomSeed; /* Debug */ DBG_vPrintf(NODE_TRACE, "\n%d NODE < NODE_vInit()", NODE_sData.u32Timer); /* Seed the pseudo random number generator using the hardware random gen */ *((volatile uint32 *)0x02001010) |= (1 << 30); /* clear ready flag */ vAHI_StartRandomNumberGenerator(TRUE /* single shot */, FALSE /* no ints */); while (!bAHI_RndNumPoll()); u32RandomSeed = ((uint32)u16AHI_ReadRandomNumber()) << 16; *((volatile uint32 *)0x02001010) |= (1 << 30); /* clear ready flag */ vAHI_StartRandomNumberGenerator(TRUE /* single shot */, FALSE /* no ints */); while (!bAHI_RndNumPoll()); u32RandomSeed |= u16AHI_ReadRandomNumber(); RND_vInit(u32RandomSeed); DBG_vPrintf(NODE_TRACE, " RND=%08x", u32RandomSeed); /* Initialise JenOS modules */ PWRM_vInit(E_AHI_SLEEP_OSCON_RAMON); DBG_vPrintf(NODE_TRACE, " PWRM"); /* Initialise persistent data */ PDM_vInit(7, 1, 64*1024, NULL, mutexPdmMedia, NULL, NULL); DBG_vPrintf(NODE_TRACE, " PDM"); /* Delete persistent data - always start over for now */ PDM_vDelete(); DBG_vPrintf(NODE_TRACE, "deleted"); PDUM_vInit(); DBG_vPrintf(NODE_TRACE, " PDUM"); /* Initialise ZigbeePro stack */ ZPS_eAplAfInit(); DBG_vPrintf(NODE_TRACE, " ZPS"); /* No state yet */ NODE_sData.eNwkState = NODE_NWKSTATE_NONE; /* Initialise non-zero node structure members */ NODE_sData.u64Address = *(uint64 *) pvAppApiGetMacAddrLocation(); /**< Address of node */ NODE_sData.u16Address = 0xffff; /**< Short address of node */ NODE_sData.u16Parent = 0xffff; /**< Short address of node's parent */ /* Initialise node structure pointer members */ NODE_sData.pvMac = (void *) pvAppApiGetMacHandle(); NODE_sData.psPib = MAC_psPibGetHandle(NODE_sData.pvMac); NODE_sData.pvNwk = ZPS_pvNwkGetHandle(); NODE_sData.psNib = ZPS_psNwkNibGetHandle(NODE_sData.pvNwk); /* Note initial MinBe */ NODE_sData.u8DefPibMinBe = NODE_sData.psPib->u8MinBe_ReadOnly; }
/**************************************************************************** * * NAME: vInitSystem * * DESCRIPTION: Initialise the radio system * * RETURNS: * void * ****************************************************************************/ PRIVATE void vInitSystem(void) { // Setup interface to MAC (void) u32AHI_Init(); (void) u32AppQApiInit(NULL,mcpsCallback , NULL); loadSettings(); if (useHighPowerModule == TRUE) { //max power for europe including antenna gain is 10dBm // TODO see if we can use more power as rx antenna is lower gain //??? boost is +2.5 ant is 1 and power set to 4 = 7.5 ???? vAHI_HighPowerModuleEnable(TRUE, TRUE); #ifdef JN5168 eAppApiPlmeSet(PHY_PIB_ATTR_TX_POWER, 34+10*2); #else bAHI_PhyRadioSetPower(2); #endif } // Initialise end device state sEndDeviceData.eState = E_STATE_IDLE; sEndDeviceData.u8TxPacketSeqNb = 0; sEndDeviceData.u8RxPacketSeqNb = 0; sEndDeviceData.u8ChannelSeqNo = 0; // Set up the MAC handles. Must be called AFTER u32AppQApiInit() s_pvMac = pvAppApiGetMacHandle(); s_psMacPib = MAC_psPibGetHandle(s_pvMac); // Set Pan ID in PIB (also sets match register in hardware) MAC_vPibSetPanId(s_pvMac, PAN_ID); // Enable receiver to be on when idle MAC_vPibSetRxOnWhenIdle(s_pvMac, TRUE, FALSE); // sometimes useful during development // all messages are passed up from lower levels // MAC_vPibSetPromiscuousMode(s_pvMac, TRUE, FALSE); module_MAC_ExtAddr_s* macptr = (module_MAC_ExtAddr_s*)pvAppApiGetMacAddrLocation(); //moved to after u32AHI_Init() for jn5148 randomizeHopSequence(((uint32) macptr->u32H) ^ ((uint32) macptr->u32L)); #if (defined JN5148 || defined JN5168) /* Enable TOF ranging. */ // vAppApiTofInit(TRUE); #endif }
void ieee_init() { void *mac; MAC_Pib_s *pib; if (process_is_running(&ieee_process)) return; /* initialize ieee_eventhandler and event queue*/ rxq_init(); /* setup mac <-> app interface */ u32AppApiInit((PR_GET_BUFFER) rxq_mlme_alloc, (PR_POST_CALLBACK) ieee_process_poll, NULL, (PR_GET_BUFFER) rxq_mcps_alloc, (PR_POST_CALLBACK) ieee_process_poll, NULL); /* get mac and pib handles */ mac = pvAppApiGetMacHandle(); pib = MAC_psPibGetHandle(mac); /* do a full reset */ req_reset(true); /* set panid and default parameters */ MAC_vPibSetPanId(mac, IEEE802154_PANDID); MAC_vPibSetRxOnWhenIdle(mac, true, false); /* allocate an event for this process */ ieee_event = process_alloc_event(); pib->bAutoRequest = true; /* bandwidth control, smaller interframe gap and higher data rate, * this is not standard conform! */ #if defined(__BA2__) && defined(JENNIC_CONF_JN5148_FASTDATARATE) vAHI_BbcSetHigherDataRate(E_AHI_BBC_CTRL_DATA_RATE_1_MBPS); vAHI_BbcSetInterFrameGap(48); #endif process_start(&ieee_process, NULL); }
int start_sniffer(int channel) { void *mac; MAC_Pib_s *pib; int res; rxq_init(); /* setup mac <-> app interface */ u32AppApiInit((PR_GET_BUFFER) rxq_mlme_alloc, (PR_POST_CALLBACK) dummy, NULL, (PR_GET_BUFFER) rxq_mcps_alloc, (PR_POST_CALLBACK) dummy, NULL); /* get mac and pib handles */ mac = pvAppApiGetMacHandle(); pib = MAC_psPibGetHandle(mac); /* do a full reset */ req_reset(true); MAC_vPibSetShortAddr(mac, 0x0001); MAC_vPibSetPromiscuousMode(mac, true, true); res = req_start(channel, true); MAC_vPibSetPromiscuousMode(mac, true, false); return res; }