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);
}
Beispiel #2
0
void
init_net(void)
{
  /* load link-layer address */
  memcpy(uip_lladdr.addr,ieee_get_mac(), sizeof(uip_lladdr.addr));
  netstack_init();
}
void
init_net(void)
{
  uip_ipaddr_t ipaddr;
  uip_ip6addr(&ipaddr, 0xaaaa, 0, 0, 0, 0, 0, 0, 0);

  /* load the mac address */
  memcpy(uip_lladdr.addr, ieee_get_mac(), sizeof(uip_lladdr.addr));

#if UIP_CONF_ROUTER
  uip_ds6_prefix_add(&ipaddr, UIP_DEFAULT_PREFIX_LEN, 0, 0, 0, 0);
#else /* UIP_CONF_ROUTER */
  uip_ds6_prefix_add(&ipaddr, UIP_DEFAULT_PREFIX_LEN, 0);
#endif /* UIP_CONF_ROUTER */
  uip_ds6_set_addr_iid(&ipaddr, &uip_lladdr);
  uip_ds6_addr_add(&ipaddr, 0, ADDR_AUTOCONF);

  netstack_init();
}
Beispiel #4
0
/* contiki mac driver functions */
void /* put packet into transmit buffer */
ieee_send(mac_callback_t cb, void *ptr)
{
  MAC_McpsReqRsp_s    req;
  MAC_McpsSyncCfm_s   cfm;

  if(!ieee_started)
    return;

  mac_cb = cb;
  mac_cb_ptr = ptr;

  /* check buffer size */
  if(packetbuf_datalen() > MAC_MAX_DATA_PAYLOAD_LEN)
    return;

  /* prepare packet request */
  req.u8Type = MAC_MCPS_REQ_DATA;
  req.u8ParamLength = sizeof(MAC_McpsReqData_s);
  req.uParam.sReqData.u8Handle = packetbuf_attr(PACKETBUF_ATTR_PACKET_ID);
  req.uParam.sReqData.sFrame.u8TxOptions = packetbuf_attr(PACKETBUF_ATTR_RELIABLE) ? MAC_TX_OPTION_ACK : 0;

  /* fill in destination address. */
  if(rimeaddr_cmp(packetbuf_addr(PACKETBUF_ADDR_RECEIVER), &rimeaddr_null))
  {
    req.uParam.sReqData.sFrame.sDstAddr.u8AddrMode     = SHORT;
    req.uParam.sReqData.sFrame.sDstAddr.u16PanId       = BROADCAST_PANID;
    req.uParam.sReqData.sFrame.sDstAddr.uAddr.u16Short = BROADCAST_ADDR;
  }
  else
  {
    req.uParam.sReqData.sFrame.sDstAddr.u8AddrMode      = LONG;
    req.uParam.sReqData.sFrame.sDstAddr.u16PanId        = IEEE802154_PANDID;
    req.uParam.sReqData.sFrame.sDstAddr.uAddr.sExt.u32H =
      ((MAC_ExtAddr_s*) packetbuf_addr(PACKETBUF_ADDR_RECEIVER))->u32L;
    req.uParam.sReqData.sFrame.sDstAddr.uAddr.sExt.u32L =
      ((MAC_ExtAddr_s*) packetbuf_addr(PACKETBUF_ADDR_RECEIVER))->u32H;
  }

  /* fill in source address */
  req.uParam.sReqData.sFrame.sSrcAddr.u8AddrMode      = LONG;
  req.uParam.sReqData.sFrame.sSrcAddr.u16PanId        = IEEE802154_PANDID;
  req.uParam.sReqData.sFrame.sSrcAddr.uAddr.sExt.u32H =
    ((MAC_ExtAddr_s*) ieee_get_mac())->u32L;
  req.uParam.sReqData.sFrame.sSrcAddr.uAddr.sExt.u32L =
    ((MAC_ExtAddr_s*) ieee_get_mac())->u32H;

//  printf("mac addr: 0x%x%x 0x%x lladdr: 0x%x%x%x%x%x%x%x%x 0x%x%x\n",
//                                    *((uint32_t*) pvAppApiGetMacAddrLocation()),
//                                    *((uint32_t*) pvAppApiGetMacAddrLocation()+1),
//                                    pvAppApiGetMacAddrLocation(),
//                                    (int) uip_lladdr.addr[0],
//                                    (int) uip_lladdr.addr[1],
//                                    (int) uip_lladdr.addr[2],
//                                    (int) uip_lladdr.addr[3],
//                                    (int) uip_lladdr.addr[4],
//                                    (int) uip_lladdr.addr[5],
//                                    (int) uip_lladdr.addr[6],
//                                    (int) uip_lladdr.addr[7],
//                                    *((uint32_t*) uip_lladdr.addr),
//                                    *((uint32_t*) uip_lladdr.addr+1));

  /* copy over payload */
  req.uParam.sReqData.sFrame.u8SduLength = packetbuf_datalen();
  memcpy( req.uParam.sReqData.sFrame.au8Sdu, packetbuf_dataptr(),
          MIN(packetbuf_datalen(), MAC_MAX_DATA_PAYLOAD_LEN) );

  while (bTACframeInProgress())
    ;

  GDB2_PUTS(".");
  vAppApiMcpsRequest(&req, &cfm);

  switch(cfm.u8Status) {
    case MAC_MCPS_CFM_OK:
      mac_call_sent_callback(mac_cb, mac_cb_ptr, MAC_TX_OK, 1);
      break;
    case MAC_MCPS_CFM_DEFERRED:
      mac_call_sent_callback(mac_cb, mac_cb_ptr, MAC_TX_DEFERRED, 1);
      break;
    default:
      mac_call_sent_callback(mac_cb, mac_cb_ptr, MAC_TX_ERR, 1);
      break;
  }

  return;
}