Beispiel #1
0
void gnrc_ipv6_nc_remove(kernel_pid_t iface, const ipv6_addr_t *ipv6_addr)
{
    gnrc_ipv6_nc_t *entry = gnrc_ipv6_nc_get(iface, ipv6_addr);

    if (entry != NULL) {
        DEBUG("ipv6_nc: Remove %s for interface %" PRIkernel_pid "\n",
              ipv6_addr_to_str(addr_str, ipv6_addr, sizeof(addr_str)),
              iface);

#ifdef MODULE_GNRC_NDP_NODE
        while (entry->pkts != NULL) {
            gnrc_pktbuf_release(entry->pkts->pkt);
            entry->pkts->pkt = NULL;
            gnrc_pktqueue_remove_head(&entry->pkts);
        }
#endif
#ifdef MODULE_GNRC_SIXLOWPAN_ND_ROUTER
        xtimer_remove(&entry->type_timeout);
#endif
#if defined(MODULE_GNRC_NDP_ROUTER) || defined(MODULE_GNRC_SIXLOWPAN_ND_BORDER_ROUTER)
        xtimer_remove(&entry->rtr_adv_timer);
#endif

        ipv6_addr_set_unspecified(&(entry->ipv6_addr));
        entry->iface = KERNEL_PID_UNDEF;
        entry->flags = 0;
    }
}
Beispiel #2
0
void sx127x_set_standby(sx127x_t *dev)
{
    DEBUG("[sx127x] Set standby\n");

    /* Disable running timers */
    xtimer_remove(&dev->_internal.tx_timeout_timer);
    xtimer_remove(&dev->_internal.rx_timeout_timer);

    sx127x_set_op_mode(dev, SX127X_RF_OPMODE_STANDBY);
    sx127x_set_state(dev,  SX127X_RF_IDLE);
}
Beispiel #3
0
void sx127x_set_sleep(sx127x_t *dev)
{
    DEBUG("[sx127x] Set sleep\n");

    /* Disable running timers */
    xtimer_remove(&dev->_internal.tx_timeout_timer);
    xtimer_remove(&dev->_internal.rx_timeout_timer);

    /* Put chip into sleep */
    sx127x_set_op_mode(dev, SX127X_RF_OPMODE_SLEEP);
    sx127x_set_state(dev,  SX127X_RF_IDLE);
}
Beispiel #4
0
int gnrc_tftp_server(tftp_data_cb_t data_cb, tftp_start_cb_t start_cb, tftp_stop_cb_t stop_cb, bool use_options)
{
    /* check if there is only one TFTP server running */
    if (_tftp_kernel_pid != KERNEL_PID_UNDEF) {
        DEBUG("tftp: only one TFTP server allowed\n");
        return -1;
    }

    /* context will be initialized when a connection is established */
    tftp_context_t ctxt;
    ctxt.data_cb = data_cb;
    ctxt.start_cb = start_cb;
    ctxt.stop_cb = stop_cb;
    ctxt.enable_options = use_options;

    /* validate our arguments */
    assert(data_cb);
    assert(start_cb);
    assert(stop_cb);

    /* save our kernel PID */
    _tftp_kernel_pid = thread_getpid();

    /* start the server */
    int ret = _tftp_server(&ctxt);

    /* remove possibly stale timer */
    xtimer_remove(&(ctxt.timer));

    /* reset the kernel PID */
    _tftp_kernel_pid = KERNEL_PID_UNDEF;

    return ret;
}
Beispiel #5
0
static inline void _lwmac_clear_timeout(gnrc_lwmac_timeout_t *timeout)
{
    assert(timeout);

    xtimer_remove(&(timeout->timer));
    timeout->type = GNRC_LWMAC_TIMEOUT_DISABLED;
}
Beispiel #6
0
int gnrc_tftp_client_write(ipv6_addr_t *addr, const char *file_name, tftp_mode_t mode,
                           tftp_data_cb_t data_cb, size_t total_size, tftp_stop_cb_t stop_cb, bool use_option_extensions)
{
    tftp_context_t ctxt;

    assert(data_cb);
    assert(stop_cb);

    /* prepare the context */
    if (_tftp_init_ctxt(addr, file_name, TO_WRQ, mode, CT_CLIENT, NULL, stop_cb, data_cb, use_option_extensions, &ctxt) < 0) {
        return -EINVAL;
    }

    /* set the transfer options */
    uint16_t mtu = _tftp_get_maximum_block_size();
    if (!use_option_extensions ||
        _tftp_set_opts(&ctxt, mtu, GNRC_TFTP_DEFAULT_TIMEOUT, total_size) != TS_FINISHED) {

        _tftp_set_default_options(&ctxt);

        if (use_option_extensions) {
            return -EINVAL;
        }
    }

    /* start the process */
    int ret = _tftp_do_client_transfer(&ctxt);

    /* remove possibly stale timer */
    xtimer_remove(&(ctxt.timer));

    return ret;
}
Beispiel #7
0
static uint_fast8_t i2c_ctrl_blocking(uint_fast8_t flags)
{
#ifdef MODULE_XTIMER
    const unsigned int xtimer_timeout = 3 * (DATA_BITS + ACK_BITS) * US_PER_SEC / speed_hz;
#endif

    mutex_trylock(&i2c_wait_mutex);

    assert(I2CM_IMR & 1);
    i2cm_ctrl_write(flags);

#ifdef MODULE_XTIMER
    /* Set a timeout at double the expected time to transmit a byte: */
    xtimer_t xtimer = { .callback = _timer_cb, .arg = NULL };
    xtimer_set(&xtimer, xtimer_timeout);
#endif

    mutex_lock(&i2c_wait_mutex);

#ifdef MODULE_XTIMER
    xtimer_remove(&xtimer);
#endif

    if (I2CM_STAT & BUSY) {
        /* If the controller is still busy, it probably will be forever */
#ifdef MODULE_XTIMER
        DEBUG("Master is still BUSY after %u usec. Resetting.\n", xtimer_timeout);
#endif
        cc2538_i2c_init_master(speed_hz);
    }

    WARN_IF(I2CM_STAT & BUSY);

    return I2CM_STAT;
}
Beispiel #8
0
/**
 * @brief   Sends @ref GNRC_NETAPI_MSG_TYPE_SND delayed.
 *
 * @param[in] t         Timer for the delay.
 * @param[in] msg       Msg for the timer.
 * @param[in] interval  Delay interval.
 * @param[in] pkt       Packet to send delayed.
 */
static inline void _send_delayed(xtimer_t *t, msg_t *msg, uint32_t interval, gnrc_pktsnip_t *pkt)
{
    xtimer_remove(t);
    msg->type = GNRC_NETAPI_MSG_TYPE_SND;
    msg->content.ptr = (char *) pkt;
    xtimer_set_msg(t, interval, msg, gnrc_ipv6_pid);
}
Beispiel #9
0
static int syncsend(uint8_t resp, size_t len, bool unlock)
{
    int res = EMCUTE_TIMEOUT;
    waiton = resp;
    timer.arg = (void *)sched_active_thread;
    /* clear flags, in case the timer was triggered last time right before the
     * remove was called */
    thread_flags_clear(TFLAGS_ANY);

    for (unsigned retries = 0; retries <= EMCUTE_N_RETRY; retries++) {
        DEBUG("[emcute] syncsend: sending round %i\n", retries);
        sock_udp_send(&sock, tbuf, len, &gateway);

        xtimer_set(&timer, (EMCUTE_T_RETRY * US_PER_SEC));
        thread_flags_t flags = thread_flags_wait_any(TFLAGS_ANY);
        if (flags & TFLAGS_RESP) {
            DEBUG("[emcute] syncsend: got response [%i]\n", result);
            xtimer_remove(&timer);
            res = result;
            break;
        }
    }

    /* cleanup sync state */
    waiton = 0xff;
    if (unlock) {
        mutex_unlock(&txlock);
    }
    return res;
}
Beispiel #10
0
/* router-only functions from net/gnrc/sixlowpan/nd.h */
void gnrc_sixlowpan_nd_opt_abr_handle(kernel_pid_t iface, ndp_rtr_adv_t *rtr_adv, int sicmpv6_size,
                                      sixlowpan_nd_opt_abr_t *abr_opt)
{
    uint16_t opt_offset = 0;
    uint8_t *buf = (uint8_t *)(rtr_adv + 1);
    gnrc_sixlowpan_nd_router_abr_t *abr;
    timex_t t = { 0, 0 };

    if (_is_me(&abr_opt->braddr)) {
        return;
    }
    /* validity and version was checked in previously called
     * gnrc_sixlowpan_nd_router_abr_older() */
    abr = _get_abr(&abr_opt->braddr);

    if (abr == NULL) {
        return;
    }

    abr->ltime = byteorder_ntohs(abr_opt->ltime);

    if (abr->ltime == 0) {
        abr->ltime = GNRC_SIXLOWPAN_ND_BORDER_ROUTER_DEFAULT_LTIME;
        return;
    }

    sicmpv6_size -= sizeof(ndp_rtr_adv_t);

    while (sicmpv6_size > 0) {
        ndp_opt_t *opt = (ndp_opt_t *)(buf + opt_offset);

        switch (opt->type) {
            case NDP_OPT_PI:
                _add_prefix(iface, abr, (ndp_opt_pi_t *)opt);

            case NDP_OPT_6CTX:
                _add_ctx(abr, (sixlowpan_nd_opt_6ctx_t *)opt);

            default:
                break;
        }

        opt_offset += (opt->len * 8);
        sicmpv6_size -= (opt->len * 8);
    }

    abr->version = (uint32_t)byteorder_ntohs(abr_opt->vlow);
    abr->version |= ((uint32_t)byteorder_ntohs(abr_opt->vhigh)) << 16;
    abr->addr.u64[0] = abr_opt->braddr.u64[0];
    abr->addr.u64[1] = abr_opt->braddr.u64[1];
    memset(abr->ctxs, 0, sizeof(abr->ctxs));
    abr->prfs = NULL;

    t.seconds = abr->ltime * 60;

    xtimer_remove(&abr->ltimer);
    abr->ltimer_msg.type = GNRC_SIXLOWPAN_ND_MSG_ABR_TIMEOUT;
    abr->ltimer_msg.content.ptr = (char *) abr;
    xtimer_set_msg(&abr->ltimer, (uint32_t) timex_uint64(t), &abr->ltimer_msg, gnrc_ipv6_pid);
}
Beispiel #11
0
static inline void _reschedule_rtr_sol(gnrc_ipv6_netif_t *iface, uint32_t delay)
{
    xtimer_remove(&iface->rtr_sol_timer);
    iface->rtr_sol_msg.type = GNRC_NDP_MSG_RTR_SOL_RETRANS;
    iface->rtr_sol_msg.content.ptr = iface;
    xtimer_set_msg(&iface->rtr_sol_timer, delay, &iface->rtr_sol_msg, gnrc_ipv6_pid);
}
Beispiel #12
0
/**
 * @brief Restarts timewait timer.
 *
 * @param[in,out] tcb   TCB holding the timer struct to reset.
 *
 * @return   Zero on success.
 */
static int _restart_timewait_timer(gnrc_tcp_tcb_t *tcb)
{
    xtimer_remove(&tcb->tim_tout);
    tcb->msg_tout.type = MSG_TYPE_TIMEWAIT;
    tcb->msg_tout.content.ptr = (void *)tcb;
    xtimer_set_msg(&tcb->tim_tout, 2 * GNRC_TCP_MSL, &tcb->msg_tout, gnrc_tcp_pid);
    return 0;
}
Beispiel #13
0
static inline void _rtr_sol_reschedule(gnrc_ipv6_netif_t *iface, uint32_t sec_delay)
{
    xtimer_remove(&iface->rtr_sol_timer);
    iface->rtr_sol_msg.type = GNRC_SIXLOWPAN_ND_MSG_MC_RTR_SOL;
    iface->rtr_sol_msg.content.ptr = (char *) iface;
    xtimer_set_msg(&iface->rtr_sol_timer, sec_delay * SEC_IN_USEC, &iface->rtr_sol_msg,
                   gnrc_ipv6_pid);
}
Beispiel #14
0
/* Listen for an incoming CoAP message. */
static void _listen(sock_udp_t *sock)
{
    coap_pkt_t pdu;
    uint8_t buf[GCOAP_PDU_BUF_SIZE];
    sock_udp_ep_t remote;
    gcoap_request_memo_t *memo = NULL;
    uint8_t open_reqs = gcoap_op_state();

    ssize_t res = sock_udp_recv(sock, buf, sizeof(buf),
                                open_reqs > 0 ? GCOAP_RECV_TIMEOUT : SOCK_NO_TIMEOUT,
                                &remote);
    if (res <= 0) {
#if ENABLE_DEBUG
        if (res < 0 && res != -ETIMEDOUT) {
            DEBUG("gcoap: udp recv failure: %d\n", res);
        }
#endif
        return;
    }

    res = coap_parse(&pdu, buf, res);
    if (res < 0) {
        DEBUG("gcoap: parse failure: %d\n", res);
        /* If a response, can't clear memo, but it will timeout later. */
        return;
    }

    if (pdu.hdr->code == COAP_CODE_EMPTY) {
        DEBUG("gcoap: empty messages not handled yet\n");
        return;

    /* incoming request */
    } else if (coap_get_code_class(&pdu) == COAP_CLASS_REQ) {
        if (coap_get_type(&pdu) == COAP_TYPE_NON
                || coap_get_type(&pdu) == COAP_TYPE_CON) {
            size_t pdu_len = _handle_req(&pdu, buf, sizeof(buf), &remote);
            if (pdu_len > 0) {
                sock_udp_send(sock, buf, pdu_len, &remote);
            }
        }
        else {
            DEBUG("gcoap: illegal request type: %u\n", coap_get_type(&pdu));
            return;
        }
    }

    /* incoming response */
    else {
        _find_req_memo(&memo, &pdu, &remote);
        if (memo) {
            xtimer_remove(&memo->response_timer);
            memo->state = GCOAP_MEMO_RESP;
            memo->resp_handler(memo->state, &pdu, &remote);
            memo->state = GCOAP_MEMO_UNUSED;
        }
    }
}
Beispiel #15
0
/**
 * @brief Clears retransmit queue.
 *
 * @param[in,out] tcb   TCB holding the retransmit queue.
 *
 * @return   Zero on success.
 */
static int _clear_retransmit(gnrc_tcp_tcb_t *tcb)
{
    if (tcb->pkt_retransmit != NULL) {
        gnrc_pktbuf_release(tcb->pkt_retransmit);
        xtimer_remove(&(tcb->tim_tout));
        tcb->pkt_retransmit = NULL;
    }
    return 0;
}
Beispiel #16
0
static void _update_timer(evtimer_t *evtimer)
{
    if (evtimer->events) {
        evtimer_event_t *event = evtimer->events;
        _set_timer(&evtimer->timer, event->offset);
    }
    else {
        xtimer_remove(&evtimer->timer);
    }
}
Beispiel #17
0
static void _api_at_cmd(xbee_t *dev, uint8_t *cmd, uint8_t size, resp_t *resp)
{
    DEBUG("[xbee] AT_CMD: %s\n", cmd);

    /* acquire TX lock */
    mutex_lock(&(dev->tx_lock));
    /* construct API frame */
    dev->cmd_buf[0] = API_START_DELIMITER;
    dev->cmd_buf[1] = (size + 2) >> 8;
    dev->cmd_buf[2] = (size + 2) & 0xff;
    dev->cmd_buf[3] = API_ID_AT;
    dev->cmd_buf[4] = 1;             /* use fixed frame id */
    memcpy(dev->cmd_buf + 5, cmd, size);
    dev->cmd_buf[size + 5] = _cksum(3, dev->cmd_buf, size + 5);

    /* reset the response data counter */
    dev->resp_count = 0;
    /* start send data */
    uart_write(dev->p.uart, dev->cmd_buf, size + 6);

    xtimer_ticks64_t sent_time = xtimer_now64();

    xtimer_t resp_timer;

    resp_timer.callback = isr_resp_timeout;
    resp_timer.arg = dev;

    xtimer_set(&resp_timer, RESP_TIMEOUT_USEC);

    /* wait for results */
    while ((dev->resp_limit != dev->resp_count) &&
           (xtimer_less(
                xtimer_diff32_64(xtimer_now64(), sent_time),
                xtimer_ticks_from_usec(RESP_TIMEOUT_USEC)))) {
        mutex_lock(&(dev->resp_lock));
    }

    xtimer_remove(&resp_timer);

    if (dev->resp_limit != dev->resp_count) {
        DEBUG("[xbee] api_at_cmd: response timeout\n");
        resp->status = 255;
        mutex_unlock(&(dev->tx_lock));

        return;
    }

    /* populate response data structure */
    resp->status = dev->resp_buf[3];
    resp->data_len = dev->resp_limit - 5;
    if (resp->data_len > 0) {
        memcpy(resp->data, &(dev->resp_buf[4]), resp->data_len);
    }
    mutex_unlock(&(dev->tx_lock));
}
Beispiel #18
0
void gnrc_gomach_clear_timeout(gnrc_netif_t *netif, gnrc_gomach_timeout_type_t type)
{
    assert(netif);

    int index = _gomach_find_timeout(&netif->mac.prot.gomach, type);
    if (index >= 0) {
        xtimer_remove(&(netif->mac.prot.gomach.timeouts[index].timer));
        netif->mac.prot.gomach.timeouts[index].type = GNRC_GOMACH_TIMEOUT_DISABLED;
        netif->mac.prot.gomach.timeouts[index].expired = false;
    }
}
Beispiel #19
0
void gnrc_sixlowpan_nd_rtr_sol_reschedule(gnrc_ipv6_nc_t *nce, uint32_t sec_delay)
{
    assert(nce != NULL);
    assert(sec_delay != 0U);
    gnrc_ipv6_netif_t *iface = gnrc_ipv6_netif_get(nce->iface);
    xtimer_remove(&iface->rtr_sol_timer);
    iface->rtr_sol_msg.type = GNRC_SIXLOWPAN_ND_MSG_MC_RTR_SOL;
    iface->rtr_sol_msg.content.ptr = (char *) iface;
    xtimer_set_msg(&iface->rtr_sol_timer, sec_delay * SEC_IN_USEC, &iface->rtr_sol_msg,
                   gnrc_ipv6_pid);
}
Beispiel #20
0
void gnrc_gomach_reset_timeouts(gnrc_netif_t *netif)
{
    assert(netif);

    for (unsigned i = 0; i < GNRC_GOMACH_TIMEOUT_COUNT; i++) {
        if (netif->mac.prot.gomach.timeouts[i].type != GNRC_GOMACH_TIMEOUT_DISABLED) {
            xtimer_remove(&(netif->mac.prot.gomach.timeouts[i].timer));
            netif->mac.prot.gomach.timeouts[i].type = GNRC_GOMACH_TIMEOUT_DISABLED;
        }
    }
}
Beispiel #21
0
static int _recv(netdev_t *netdev, void *buf, size_t len, void *info)
{
    sx127x_t *dev = (sx127x_t*) netdev;
    volatile uint8_t irq_flags = 0;
    uint8_t size = 0;
    switch (dev->settings.modem) {
        case SX127X_MODEM_FSK:
            /* todo */
            break;
        case SX127X_MODEM_LORA:
            /* Clear IRQ */
            sx127x_reg_write(dev, SX127X_REG_LR_IRQFLAGS, SX127X_RF_LORA_IRQFLAGS_RXDONE);

            irq_flags = sx127x_reg_read(dev, SX127X_REG_LR_IRQFLAGS);
            if ( (irq_flags & SX127X_RF_LORA_IRQFLAGS_PAYLOADCRCERROR_MASK) ==
                 SX127X_RF_LORA_IRQFLAGS_PAYLOADCRCERROR) {
                /* Clear IRQ */
                sx127x_reg_write(dev, SX127X_REG_LR_IRQFLAGS,
                                 SX127X_RF_LORA_IRQFLAGS_PAYLOADCRCERROR);

                if (!(dev->settings.lora.flags & SX127X_RX_CONTINUOUS_FLAG)) {
                    sx127x_set_state(dev, SX127X_RF_IDLE);
                }

                xtimer_remove(&dev->_internal.rx_timeout_timer);
                netdev->event_callback(netdev, NETDEV_EVENT_CRC_ERROR);
                return -EBADMSG;
            }

            netdev_sx127x_lora_packet_info_t *packet_info = info;
            if (packet_info) {
                /* there is no LQI for LoRa */
                packet_info->lqi = 0;
                uint8_t snr_value = sx127x_reg_read(dev, SX127X_REG_LR_PKTSNRVALUE);
                if (snr_value & 0x80) { /* The SNR is negative */
                    /* Invert and divide by 4 */
                    packet_info->snr = -1 * ((~snr_value + 1) & 0xFF) >> 2;
                }
                else {
                    /* Divide by 4 */
                    packet_info->snr = (snr_value & 0xFF) >> 2;
                }

                int16_t rssi = sx127x_reg_read(dev, SX127X_REG_LR_PKTRSSIVALUE);

                if (packet_info->snr < 0) {
#if defined(MODULE_SX1272)
                    packet_info->rssi = SX127X_RSSI_OFFSET + rssi + (rssi >> 4) + packet_info->snr;
#else /* MODULE_SX1276 */
                    if (dev->settings.channel > SX127X_RF_MID_BAND_THRESH) {
                        packet_info->rssi = SX127X_RSSI_OFFSET_HF + rssi + (rssi >> 4) + packet_info->snr;
                    }
Beispiel #22
0
static void _ipv6_netif_remove(gnrc_ipv6_netif_t *entry)
{
    if (entry == NULL) {
        return;
    }

#ifdef MODULE_GNRC_NDP
    gnrc_ndp_netif_remove(entry);
#endif

    mutex_lock(&entry->mutex);
    xtimer_remove(&entry->rtr_sol_timer);
#ifdef MODULE_GNRC_NDP_ROUTER
    xtimer_remove(&entry->rtr_adv_timer);
#endif
    _reset_addr_from_entry(entry);
    DEBUG("ipv6 netif: Remove IPv6 interface %" PRIkernel_pid "\n", entry->pid);
    entry->pid = KERNEL_PID_UNDEF;
    entry->flags = 0;

    mutex_unlock(&entry->mutex);
}
Beispiel #23
0
bool gnrc_gomach_timeout_is_expired(gnrc_netif_t *netif, gnrc_gomach_timeout_type_t type)
{
    assert(netif);

    int index = _gomach_find_timeout(&netif->mac.prot.gomach, type);
    if (index >= 0) {
        if (netif->mac.prot.gomach.timeouts[index].expired) {
            xtimer_remove(&(netif->mac.prot.gomach.timeouts[index].timer));
            netif->mac.prot.gomach.timeouts[index].type = GNRC_GOMACH_TIMEOUT_DISABLED;
        }
        return netif->mac.prot.gomach.timeouts[index].expired;
    }
    return false;
}
Beispiel #24
0
cv_status condition_variable::wait_until(unique_lock<mutex>& lock,
                                         const time_point& timeout_time) {
  xtimer_t timer;
  // todo: use function to wait for absolute timepoint once available
  timex_t before;
  xtimer_now_timex(&before);
  auto diff = timex_sub(timeout_time.native_handle(), before);
  xtimer_set_wakeup(&timer, timex_uint64(diff), sched_active_pid);
  wait(lock);
  timex_t after;
  xtimer_now_timex(&after);
  xtimer_remove(&timer);
  auto cmp = timex_cmp(after, timeout_time.native_handle());
  return cmp < 1 ? cv_status::no_timeout : cv_status::timeout;
}
Beispiel #25
0
void xtimer_set(xtimer_t *timer, uint32_t offset)
{
    DEBUG("timer_set(): offset=%" PRIu32 " now=%" PRIu32 " (%" PRIu32 ")\n", offset, xtimer_now(), _xtimer_now());
    if (!timer->callback) {
        DEBUG("timer_set(): timer has no callback.\n");
        return;
    }

    xtimer_remove(timer);
    uint32_t target = xtimer_now() + offset;

    if (offset < XTIMER_BACKOFF) {
        xtimer_spin(offset);
        _shoot(timer);
    }
    else {
        _xtimer_set_absolute(timer, target);
    }
}
Beispiel #26
0
int main(void)
{
    msg_t m, tmsg;
    xtimer_t t;
    int64_t offset = -1000;
    tmsg.type = 44;

    for (int i = 0; i < 10; i++) {
        xtimer_set_msg(&t, SEC_IN_USEC + offset, &tmsg, sched_active_pid);
        if (xtimer_msg_receive_timeout(&m, SEC_IN_USEC) < 0) {
            puts("Timeout!");
        }
        else {
            printf("Message received: %" PRIu16 "\n", m.type);
        }
        offset = (offset < 0) ? 1000 : -1000;
    }
    xtimer_remove(&t);
    return 0;
}
Beispiel #27
0
static void _send_rtr_adv(gnrc_ipv6_netif_t *iface, ipv6_addr_t *dst)
{
    bool fin;
    uint32_t interval;

    mutex_lock(&iface->mutex);
    fin = (iface->adv_ltime == 0);
    assert((iface->min_adv_int != 0) && (iface->max_adv_int != 0));
    interval = genrand_uint32_range(iface->min_adv_int, iface->max_adv_int);
    if (!fin && !((iface->flags | GNRC_IPV6_NETIF_FLAGS_ROUTER) &&
                  (iface->flags | GNRC_IPV6_NETIF_FLAGS_RTR_ADV))) {
        DEBUG("ndp rtr: interface %" PRIkernel_pid " is not an advertising interface\n",
              iface->pid);
        return;
    }
    if (iface->rtr_adv_count > 1) { /* regard for off-by-one error */
        iface->rtr_adv_count--;
        if (!fin && (interval > GNRC_NDP_MAX_INIT_RTR_ADV_INT)) {
            interval = GNRC_NDP_MAX_INIT_RTR_ADV_INT;
        }
    }
    if (!fin || (iface->rtr_adv_count > 1)) {   /* regard for off-by-one-error */
        /* reset timer for next router advertisement */
        xtimer_remove(&iface->rtr_adv_timer);
        iface->rtr_adv_msg.type = GNRC_NDP_MSG_RTR_ADV_RETRANS;
        iface->rtr_adv_msg.content.ptr = (char *) iface;
        xtimer_set_msg(&iface->rtr_adv_timer, interval * SEC_IN_USEC, &iface->rtr_adv_msg,
                       gnrc_ipv6_pid);
    }
    mutex_unlock(&iface->mutex);
    for (int i = 0; i < GNRC_IPV6_NETIF_ADDR_NUMOF; i++) {
        ipv6_addr_t *src = &iface->addrs[i].addr;

        if (!ipv6_addr_is_unspecified(src) && ipv6_addr_is_link_local(src) &&
            !gnrc_ipv6_netif_addr_is_non_unicast(src)) {
            /* send one for every link local address (ideally there is only one) */
            gnrc_ndp_internal_send_rtr_adv(iface->pid, src, dst, fin);
        }
    }
}
Beispiel #28
0
static int pthread_rwlock_timedlock(pthread_rwlock_t *rwlock,
                                    bool (*is_blocked)(const pthread_rwlock_t *rwlock),
                                    bool is_writer,
                                    int incr_when_held,
                                    const struct timespec *abstime)
{
    uint64_t now = xtimer_now_usec64();
    uint64_t then = ((uint64_t)abstime->tv_sec * US_PER_SEC) +
                    (abstime->tv_nsec / NS_PER_US);

    if ((then - now) <= 0) {
        return ETIMEDOUT;
    }
    else {
        xtimer_t timer;
        xtimer_set_wakeup64(&timer, (then - now), sched_active_pid);
        int result = pthread_rwlock_lock(rwlock, is_blocked, is_writer, incr_when_held, true);
        if (result != ETIMEDOUT) {
            xtimer_remove(&timer);
        }

        return result;
    }
}
Beispiel #29
0
void _xtimer_set64(xtimer_t *timer, uint32_t offset, uint32_t long_offset)
{
    DEBUG(" _xtimer_set64() offset=%" PRIu32 " long_offset=%" PRIu32 "\n", offset, long_offset);
    if (!long_offset) {
        /* timer fits into the short timer */
        xtimer_set(timer, (uint32_t) offset);
    }
    else {
        xtimer_remove(timer);

        _xtimer_now64(&timer->target, &timer->long_target);
        timer->target += offset;
        timer->long_target += long_offset;
        if (timer->target < offset) {
            timer->long_target++;
        }

        int state = disableIRQ();
        _add_timer_to_long_list(&long_list_head, timer);
        restoreIRQ(state);
        DEBUG("xtimer_set64(): added longterm timer (long_target=%" PRIu32 " target=%" PRIu32 ")\n",
                timer->long_target, timer->target);
    }
}
Beispiel #30
0
static void _nc_remove(kernel_pid_t iface, gnrc_ipv6_nc_t *entry)
{
    (void) iface;
    if (entry == NULL) {
        return;
    }

    DEBUG("ipv6_nc: Remove %s for interface %" PRIkernel_pid "\n",
          ipv6_addr_to_str(addr_str, &(entry->ipv6_addr), sizeof(addr_str)),
          iface);

#ifdef MODULE_GNRC_NDP_NODE
    while (entry->pkts != NULL) {
        gnrc_pktbuf_release(entry->pkts->pkt);
        entry->pkts->pkt = NULL;
        gnrc_pktqueue_remove_head(&entry->pkts);
    }
#endif
#ifdef MODULE_GNRC_SIXLOWPAN_ND_ROUTER
    xtimer_remove(&entry->type_timeout);

    gnrc_ipv6_netif_t *if_entry = gnrc_ipv6_netif_get(iface);

    if ((if_entry != NULL) && (if_entry->rtr_adv_msg.content.ptr == (char *) entry)) {
        /* cancel timer set by gnrc_ndp_rtr_sol_handle */
        xtimer_remove(&if_entry->rtr_adv_timer);
    }
#endif
#if defined(MODULE_GNRC_NDP_ROUTER) || defined(MODULE_GNRC_SIXLOWPAN_ND_BORDER_ROUTER)
    xtimer_remove(&entry->rtr_adv_timer);
#endif

    xtimer_remove(&entry->rtr_timeout);
    xtimer_remove(&entry->nbr_sol_timer);
    xtimer_remove(&entry->nbr_adv_timer);

    ipv6_addr_set_unspecified(&(entry->ipv6_addr));
    entry->iface = KERNEL_PID_UNDEF;
    entry->flags = 0;
}