コード例 #1
0
void zb_nwk_mesh_routing_deinit() 
{
  TRACE_MSG(TRACE_NWK1, ">> r_deinit", (FMT__0));

  ZB_SCHEDULE_ALARM_CANCEL(zb_nwk_mesh_expiry_pending, ZB_ALARM_ANY_PARAM);
  ZB_SCHEDULE_ALARM_CANCEL(zb_nwk_mesh_expiry_route_disc, ZB_ALARM_ANY_PARAM);
#if 0
  ZB_SCHEDULE_ALARM_CANCEL(zb_nwk_mesh_expiry_rreq, ZB_ALARM_ANY_PARAM);
#endif

  TRACE_MSG(TRACE_NWK1, "<< r_deinit", (FMT__0));
}
コード例 #2
0
ファイル: zdo_app.c プロジェクト: Comfee/zboss
void zb_zdo_reschedule_poll_parent(zb_uint16_t timeout)
{
  /* reschedule alarm only if we are not waiting for the poll confirm and
   * really need polls */
  if (!(MAC_PIB().mac_rx_on_when_idle
        || ZDO_CTX().inside_poll))
  {
    ZB_SCHEDULE_ALARM_CANCEL(zb_zdo_poll_parent, 0);
    /* If FFD have some pending data for us, we schedule poll w/o timeout */
    ZB_SCHEDULE_ALARM(zb_zdo_poll_parent, 0,  ZB_MAC_GET_PENDING_DATA()? 1 : timeout);
  }
}
コード例 #3
0
ファイル: mac_scan.c プロジェクト: alele89/18748-WSN
zb_ret_t zb_mlme_active_scan() 
{
  zb_ret_t ret = RET_OK;
  zb_mlme_scan_params_t *scan_params;
  zb_uint8_t channel_number;

/*
  mac spec 7.5.2.1.2 Active channel scan
  - set macPANId to 0xffff in order to accept all incoming beacons
  - switch to next channel
  - send beacon request, mac spec 7.3.7 Beacon request command
  - enable receiver for [aBaseSuperframeDuration * (2^n + 1)] symbols
  == (2^n + 1)Beacon_Intervals, n == request.ScanDuration; accept only beacon frames
  - use mode macAutoRequest == FALSE: send each beacon to the higher
  layer using MLME-BEACON-NOTIFY indication. Beacon frame can contain payload
  - if frame_control.Security Enabled == 1, unsecure the beacon frame (mac spec 7.5.8.2.3)      --- not supported now
  - if at least 1 beacon request was successfully sent but no beacons were found, set status NO_BEACON
*/

  TRACE_MSG(TRACE_MAC1, ">> zb_mlme_active_scan", (FMT__0));

  scan_params = ZB_GET_BUF_PARAM(MAC_CTX().pending_buf, zb_mlme_scan_params_t);
  ZB_ASSERT(scan_params);

  TRACE_MSG(TRACE_MAC1, "idle state, set beacon found == 0", (FMT__0));
  MAC_CTX().rt_ctx.active_scan.beacon_found = 0;
#ifdef ZB_MAC_TESTING_MODE
  MAC_CTX().rt_ctx.active_scan.pan_desc_buf_param = ZB_UNDEFINED_BUFFER;
#endif
  channel_number = ZB_MAC_START_CHANNEL_NUMBER;

  TRACE_MSG(TRACE_MAC3, "set beacon mode ret %d, param channels 0x%x", (FMT__D_D, ret, scan_params->channels));
  MAC_CTX().unscanned_channels = scan_params->channels;

#ifdef ZB_MAC_TESTING_MODE
  if (MAC_CTX().rt_ctx.active_scan.stop_scan)
  {
    ZB_SCHEDULE_ALARM_CANCEL(zb_mac_scan_timeout, 0);
    ret = RET_OK;
    break;
  }
#endif
  TRACE_MSG(TRACE_MAC2, "chan mask %x %x , chan %hd",
            (FMT__D_D_H, ((zb_uint16_t*)&scan_params->channels)[0], ((zb_uint16_t*)&scan_params->channels)[1],
             channel_number));
  ZB_SCHEDULE_CALLBACK(zb_mlme_scan_step,0);
  TRACE_MSG(TRACE_MAC1, "<< zb_mlme_active_scan, ret %i", (FMT__D, ret));
  return ret;
}
コード例 #4
0
void nwk_route_disc_failed(zb_uint8_t param) 
{
  zb_nlme_status_indication_t *status =  ZB_GET_BUF_PARAM(ZB_BUF_FROM_REF(param), zb_nlme_status_indication_t);

  TRACE_MSG(TRACE_NWK1, ">> nwk_route_disc_failed", (FMT__0));

  status->status = ZB_NWK_COMMAND_STATUS_NO_ROUTE_AVAILABLE;
  status->network_addr = ZG->nwk.handle.status_ind_addr;

  /* notify */
  ZB_SCHEDULE_CALLBACK(zb_nlme_status_indication, param);
  ZB_SCHEDULE_ALARM_CANCEL(zb_nwk_mesh_expiry_route_disc, 0);
  ZB_SCHEDULE_ALARM(zb_nwk_mesh_expiry_route_disc, 0, ZB_NWK_EXPIRY_ROUTE_DISCOVERY);

  TRACE_MSG(TRACE_NWK1, ">> nwk_route_disc_failed", (FMT__0));
}
コード例 #5
0
/*
 * Generate and send a route request command frame.
 * Add route request entry into the rreq list to be able to track this request.
*/
static zb_ret_t zb_nwk_mesh_send_rreq(zb_buf_t *cbuf, zb_nwk_cmd_rreq_t *nwk_cmd_rreq, zb_uint16_t src_addr, zb_uint8_t seq_num, zb_uint8_t path_cost, zb_uint8_t radius) 
{
  zb_ret_t ret = RET_OK;

  TRACE_MSG(TRACE_NWK1, ">> send_rreq cbuf %p rreq %p s_addr %d path_cost %hd radius %hd", (FMT__P_P_D_H_H,
                         cbuf, nwk_cmd_rreq, src_addr, path_cost, radius));

#if 0
  /* check we have room in rreq table */
  if ( ZG->nwk.nib.rreq_cnt < ZB_NWK_RREQ_TABLE_SIZE )
#endif
  {
    zb_nwk_hdr_t *nwhdr;
    zb_nwk_cmd_rreq_t *rreq_cmd;
#if 0
    zb_nwk_rreq_t *rreq;
#endif
    zb_bool_t secure = ZB_FALSE;

#ifdef ZB_SECURITY
    secure = (ZG->aps.authenticated && ZG->nwk.nib.secure_all_frames
             && ZG->nwk.nib.security_level);
#endif

    nwhdr = nwk_alloc_and_fill_hdr(cbuf,
                                   ZB_NWK_BROADCAST_ROUTER_COORDINATOR, NULL, NULL, ZB_FALSE, secure, ZB_TRUE);
    rreq_cmd = (zb_nwk_cmd_rreq_t *)nwk_alloc_and_fill_cmd(cbuf, ZB_NWK_CMD_ROUTE_REQUEST, sizeof(zb_nwk_cmd_rreq_t));
    rreq_cmd->opt = 0;
    rreq_cmd->rreq_id = nwk_cmd_rreq->rreq_id;
    rreq_cmd->dest_addr = nwk_cmd_rreq->dest_addr;
    ZB_NWK_ADDR_TO_LE16(rreq_cmd->dest_addr);
    rreq_cmd->path_cost = path_cost;
    nwhdr->radius = radius;
    nwhdr->src_addr = src_addr;

    /* Not sure it is right, but let's assign original seq_num. Else request
     * can be dropped as a dup at receiver's side. */
    if (src_addr != ZB_NIB_NETWORK_ADDRESS())
    {
      nwhdr->seq_num = seq_num;
    }

#if 0
    /* Save info to retransmit request ZB_MWK_RREQ_RETRIES times */
    NWK_ROUTING_ARRAY_GET_ENT(ZG->nwk.nib.rreq, rreq, ZG->nwk.nib.rreq_cnt);
    ZB_ASSERT(rreq);
    if ( rreq )
    {
      rreq->originator = src_addr;
      rreq->radius = radius;
      rreq->retries = 1;
      memcpy(&rreq->cmd, rreq_cmd, sizeof(rreq->cmd));

      /* schedule resend function */
      if ( ZG->nwk.nib.rreq_cnt == 1 )
      {
        ZB_SCHEDULE_ALARM_CANCEL(zb_nwk_mesh_expiry_rreq, ZB_ALARM_ANY_PARAM);
        ZB_SCHEDULE_ALARM(zb_nwk_mesh_expiry_rreq, -1, ZB_NWK_RREQ_RETRY_INTERVAL);
      }
    }
#endif

    /* transmit route request packet */
    ZB_SET_BUF_PARAM(cbuf, ZB_NWK_INTERNAL_NSDU_HANDLE, zb_uint8_t);
    ZB_SCHEDULE_CALLBACK(zb_nwk_forward, ZB_REF_FROM_BUF(cbuf));
  }
#if 0
  else
  {
    zb_free_buf(cbuf);
    TRACE_MSG(TRACE_NWK1, "rreq buffer is full", (FMT__0));
    ret = RET_NO_MEMORY;
  }
#endif

  TRACE_MSG(TRACE_NWK1, "<< send_rreq %d", (FMT__D, ret));
  return ret;
}
コード例 #6
0
ファイル: mac_scan.c プロジェクト: alele89/18748-WSN
/* this is a universal routine for ed/active/orphan scans */
void zb_mlme_scan_step(zb_uint8_t param) 
{
  zb_uint8_t channel_number;
  zb_mlme_scan_params_t *scan_params;
  zb_ret_t ret = RET_OK;
  zb_uint16_t timeout;
  zb_uint32_t *unscanned_channels;

  TRACE_MSG(TRACE_MAC1, ">> zb_mlme_scan_step", (FMT__0));
  ZVUNUSED(param);
  channel_number = ZB_MAC_START_CHANNEL_NUMBER;
  scan_params = ZB_GET_BUF_PARAM(MAC_CTX().pending_buf, zb_mlme_scan_params_t);
  /* Table 2.80   Fields of the Mgmt_NWK_Disc_req Command (the other scans
     requests are using the same parameters
     A value used to calculate the length
     of time to spend scanning each
     channel. The time spent scanning
     each channel is
     (aBaseSuperframeDuration * (2^n +
     1)) symbols, where n is the value of
     the ScanDuration parameter. */
  timeout = (1l << scan_params->scan_duration) + 1;
  MAC_CTX().mlme_scan_in_progress = 1;
  unscanned_channels = &MAC_CTX().unscanned_channels;
  for (;channel_number < ZB_MAC_START_CHANNEL_NUMBER + ZB_MAC_MAX_CHANNEL_NUMBER;channel_number++)
  {
    if (*unscanned_channels & 1l<<channel_number)
    {
      TRACE_MSG(TRACE_MAC2, "set channel %hd", (FMT__H, channel_number));
      ZB_TRANSCEIVER_SET_CHANNEL(channel_number);
      *unscanned_channels &=~(1l<<channel_number);
      if (scan_params->scan_type == ACTIVE_SCAN)
      {
        ret = zb_beacon_request_command();
        if (ret == RET_OK)
        {
          /* check beacon request TX status */
          /* There's nothing to do during active scan, so, synchronous */
          ret = zb_check_cmd_tx_status();
        }
      }
      
      ZB_SCHEDULE_ALARM_CANCEL(zb_mlme_scan_step, 0);
      ret = ZB_SCHEDULE_ALARM(zb_mlme_scan_step, 0, timeout);
      break;
    }
  }
  if (channel_number == (ZB_MAC_START_CHANNEL_NUMBER + ZB_MAC_MAX_CHANNEL_NUMBER))
  {
    zb_mac_scan_confirm_t *scan_confirm;
    /* There's no need to restore channel
       after active or orphan scan, because we will choose
       new channel, according to scan results.
    */
    /* ZB_TRANSCEIVER_SET_CHANNEL(MAC_CTX().rt_ctx.ed_scan.save_channel);*/
    scan_confirm = ZB_GET_BUF_PARAM(MAC_CTX().pending_buf, zb_mac_scan_confirm_t);
    TRACE_MSG(TRACE_MAC3, "beacon found %hd", (FMT__H, MAC_CTX().rt_ctx.active_scan.beacon_found));
    if (scan_params->scan_type == ED_SCAN || MAC_CTX().rt_ctx.active_scan.beacon_found
        || MAC_CTX().rt_ctx.orphan_scan.got_realignment)
    {
      scan_confirm->status = MAC_SUCCESS;
      /* Q: do we really need to zero here?  What about got_realignment?
       *
       * A: I think yes, because it is the only indication
       * for NO_BEACON status, that will not affect ED or ORPHAN scans. ED just
       * doesn't need any packets, and ORPHAN needs a realignment command that
       * is processed in appropriate function */
      MAC_CTX().rt_ctx.active_scan.beacon_found = 0;
    }
    else
    {
      scan_confirm->status = MAC_NO_BEACON;
    }
#ifdef ZB_MAC_TESTING_MODE
    {
      scan_confirm->result_list_size = desc_count;
    }
#endif
    scan_confirm->scan_type = scan_params->scan_type;
    MAC_CTX().mlme_scan_in_progress = 0;
    ZB_SCHEDULE_CALLBACK(zb_mlme_scan_confirm, ZB_REF_FROM_BUF(MAC_CTX().pending_buf));
  }
  TRACE_MSG(TRACE_MAC1, "<< zb_mlme_scan_step", (FMT__0));
}