void beacon_sequence() { static int beacon_seq_state = 0; switch ( beacon_seq_state ) { case 0: // send data if enough time passed since last send if ( gettime() - ble_txtime > BLE_INTERVAL ) { ble_send = 1; oldchan = rf_chan; send_beacon(); beacon_seq_state++; } break; case 1: // wait for data to finish transmitting if( (xn_readreg(0x17)&B00010000) ) { xn_writereg( 0 , XN_TO_RX ); xn_writereg(0x25, rfchannel[oldchan]); beacon_seq_state++; goto next; } else {// if it takes too long we get rid of it if ( gettime() - ble_txtime > BLE_TX_TIMEOUT ) { xn_command( FLUSH_TX); xn_writereg( 0 , XN_TO_RX ); beacon_seq_state++; ble_send = 0; } } break; case 2: next: // restore radio settings to protocol compatible // mainly channel here if bind ble_send = 0; if ( rxmode == 0 ) { xn_writereg(0x25, 0 ); // Set channel frequency , bind } beacon_seq_state++; break; default: beacon_seq_state = 0; break; } }
static int8_t nbr_msg_handler(void *state, Message *msg) { nbr_state_t *s = (nbr_state_t*)state; /** * Switch to the correct message handler */ switch (msg->type){ case MSG_INIT: { s->nb_list = NULL; s->nb_cnt = 0; s->est_ticks = 0; s->gCurrentSeqNo = 0; sys_shm_open( sys_shm_name(NBHOOD_PID, SHM_NBR_LIST), s->nb_list ); sys_timer_start(BACKOFF_TIMER, sys_rand() % 1024L, TIMER_ONE_SHOT); break; } case MSG_FINAL: { break; } case MSG_TIMER_TIMEOUT: { if( timer_get_tid( msg ) == BACKOFF_TIMER ) { sys_timer_start(NEIGHBOR_DISCOVERY_TIMER, NEIGHBOR_TIMER_INTERVAL, TIMER_REPEAT); } else { // // Send beacon packets // update_table( s ); sys_shm_update( sys_shm_name(NBHOOD_PID, SHM_NBR_LIST), s->nb_list ); send_beacon( s ); nb_debug(s); } break; } case MSG_BEACON_PKT: { // // Process beacon packets // recv_beacon( s, msg ); break; } default: return -EINVAL; } /** * Return SOS_OK for those handlers that have successfully been handled. */ return SOS_OK; }
int main(int argc, char **argv) { ros::init(argc, argv, "beacon"); ros::NodeHandle n("~"); n.param<int>("broadcast_to", broadcast_to, 9196); n.param<std::string>("broadcast_interface",broadcast_interface, "wlan0"); n.param<int>("refresh_rate",broadcast_rate, 10); pub = n.advertise<std_msgs::String>("beacon", 1000); ros::Subscriber sub = n.subscribe<std_msgs::Int32>("/portal", 50, &callback); port = -1; ros::Rate loop_rate(broadcast_rate); while(ros::ok()) { ros::spinOnce(); if(port == -1) continue; if(send_beacon(broadcast_to,broadcast_interface.c_str(),port)) { std_msgs::String str; std::stringstream ss; ss << "Sent out beacon "<< port; ss << " on "<< broadcast_to; str.data = ss.str(); //ROS_INFO("%s", str.data.c_str()); pub.publish(str); } loop_rate.sleep(); } return 0; }
// initializes state and transmits join request beacon. int8_t initiate_join( uint16_t source_addr, wcom_msg_beacon_t *beacon ){ provisional_neighbor_t *prov = add_prov( source_addr ); // check if prov was added if( prov == 0 ){ return -1; } // send a beacon with a join request to the neighbor if( send_beacon( source_addr, TRUE ) < 0 ){ // release prov remove_prov( source_addr ); // couldn't send the beacon return -1; } // setup provisional neighbor prov->state = PROVISIONAL_STATE_WAIT_FLASH; prov->short_addr = source_addr; prov->flags = beacon->flags; prov->ip = beacon->ip; prov->upstream = beacon->upstream; prov->depth = beacon->depth; log_v_debug_P( PSTR("Initiate join with:%d"), source_addr ); return 0; }
void next_event(struct params *p) { struct timeval to, now; int el; int max; fd_set fds; int rtr = 3*1000; /* figure out select timeout */ if (gettimeofday(&now, NULL) == -1) err(1, "gettimeofday()"); /* check beacon timeout */ el = elapsed(&p->blast, &now); if (el >= p->bint) { send_beacon(p); el = 0; } el = p->bint - el; to.tv_sec = el/1000/1000; to.tv_usec = el - to.tv_sec*1000*1000; /* check tx timeout */ if (p->packet_try) { el = elapsed(&p->plast, &now); if (el >= rtr) { /* check if we gotta retransmit more */ if (retransmit(p)) { el = 0; } else el = -1; } /* gotta retransmit in future */ if (el != -1) { el = rtr - el; if ((to.tv_sec*1000*1000 + to.tv_usec) > el) { to.tv_sec = el/1000/1000; to.tv_usec = el - to.tv_sec*1000*1000; } } } /* select */ FD_ZERO(&fds); FD_SET(p->rx, &fds); FD_SET(p->tap, &fds); max = p->rx > p->tap ? p->rx : p->tap; if (select(max+1, &fds, NULL, NULL, &to) == -1) err(1, "select()"); if (FD_ISSET(p->tap, &fds)) read_tap(p); if (FD_ISSET(p->rx, &fds)) read_wifi(p); }
int main(int argc, char **argv) { int listenfd, on; sockaddr_in addr; ros::init(argc, argv, "tablet_sender"); ros::NodeHandle n; n.param<int>("tablet_sender/port", port, DEFAULT_PORT); if (!(port >= 0 && port < 65536)) { ROS_ERROR("Invalid port value %d\n", port); return -1; } listenfd = socket(AF_INET, SOCK_STREAM, IPPROTO_IP); if (listenfd < 0) { ROS_ERROR("socket: %s", strerror(errno)); return -1; } on = 1; if (setsockopt(listenfd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on)) < 0) { ROS_ERROR("setsockopt: %s", strerror(errno)); close(listenfd); return -1; } memset(&addr, 0, sizeof(addr)); addr.sin_family = AF_INET; addr.sin_port = htons(port); addr.sin_addr.s_addr = htonl(INADDR_ANY); if (bind(listenfd, (const struct sockaddr *)&addr, sizeof(addr)) < 0) { ROS_ERROR("bind: %s", strerror(errno)); close(listenfd); return -1; } if (listen(listenfd, LISTEN_BACKLOG) < 0) { ROS_ERROR("listen: %s", strerror(errno)); close(listenfd); return -1; } ros::Subscriber sub_error_info = n.subscribe("error_info", QUEUE_SIZE, subscribe_error_info); ros::Subscriber sub_can_info = n.subscribe("can_info", QUEUE_SIZE, subscribe_can_info); ros::Subscriber sub_mode_info = n.subscribe("mode_info", QUEUE_SIZE, subscribe_mode_info); ros::Subscriber sub_ndt_stat = n.subscribe("ndt_stat", QUEUE_SIZE, subscribe_ndt_stat); ros::Subscriber sub_lf_stat = n.subscribe("wf_stat", QUEUE_SIZE, subscribe_lf_stat); ros::Rate loop_rate(SUBSCRIBE_HZ); struct sigaction act; sigaction(SIGINT, NULL, &act); act.sa_flags &= ~SA_RESTART; sigaction(SIGINT, &act, NULL); while (true) { connfd = accept(listenfd, (struct sockaddr *)nullptr, nullptr); if (connfd < 0) { ROS_ERROR("accept: %s", strerror(errno)); close(listenfd); return -1; } socket_ok = true; while (socket_ok && send_beacon()) { ros::spinOnce(); loop_rate.sleep(); } close(connfd); } close(listenfd); return 0; }
int main(int argc, char** argv) { const char *filepath; FILE *file; //FILE *fout; size_t cnt; __le16 seq = 0; if(argc != 2){ printf("Usage: ./tx filepath\n"); return -1; } filepath = argv[1]; printf("%s\n",filepath); //1.open file for write, byte format file=fopen(filepath,"rb"); if(file==NULL){ printf("open file error\n"); return -1; } /* fout=fopen("test.dat","w+"); if(fout==NULL){ printf("open file error\n"); return -1; } */ //2. init lorcon printf("Initializing LORCON\n"); init_lorcon(); //3. allocat packet and set header packet = malloc(sizeof(*packet) + packet_size); if (!packet) { perror("malloc packet"); exit(1); } packet->fc = (0x08 | (0x0 << 8) ); packet->dur = 0xffff; memcpy(packet->addr1, "\x00\x16\xea\x12\x34\x56", 6); memcpy(packet->addr2, "\x00\x16\xea\x12\x34\x56", 6); memcpy(packet->addr3, "\xff\xff\xff\xff\xff\xff", 6); packet->seq = seq; tx_packet.packet = (uint8_t *)packet; tx_packet.plen = sizeof(*packet) + packet_size; //4. read file and send //size and nmemb! //differ cnt == packet_size and cnt < packet_size while((cnt = fread(packet->payload,1,packet_size,file)) == packet_size){ printf("%d\n",cnt); //fwrite(packet->payload,1,cnt,fout); send_beacon(seq++); } if(cnt > 0){ printf("%d\n",cnt); //fwrite(packet->payload,1,cnt,fout); tx_packet.plen = sizeof(*packet) + cnt; send_beacon(seq++); } free(packet); fclose(file); //fclose(fout); return 0; }
static void start_bss_network(struct adapter *padapter, u8 *pbuf) { u8 *p; u8 val8, cur_channel, cur_bwmode, cur_ch_offset; u16 bcn_interval; u32 acparm; uint ie_len; struct registry_priv *pregpriv = &padapter->registrypriv; struct mlme_priv *pmlmepriv = &padapter->mlmepriv; struct security_priv *psecuritypriv = &padapter->securitypriv; struct wlan_bssid_ex *pnetwork = (struct wlan_bssid_ex *)&pmlmepriv->cur_network.network; struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv; struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info; struct wlan_bssid_ex *pnetwork_mlmeext = &pmlmeinfo->network; struct HT_info_element *pht_info = NULL; bcn_interval = (u16)pnetwork->Configuration.BeaconPeriod; cur_channel = pnetwork->Configuration.DSConfig; cur_bwmode = HT_CHANNEL_WIDTH_20; cur_ch_offset = HAL_PRIME_CHNL_OFFSET_DONT_CARE; /* check if there is wps ie, * if there is wpsie in beacon, the hostapd will update * beacon twice when stating hostapd, and at first time the * security ie (RSN/WPA IE) will not include in beacon. */ if (!rtw_get_wps_ie(pnetwork->ies + _FIXED_IE_LENGTH_, pnetwork->ie_length - _FIXED_IE_LENGTH_, NULL, NULL)) pmlmeext->bstart_bss = true; /* todo: update wmm, ht cap */ if (pmlmepriv->qospriv.qos_option) pmlmeinfo->WMM_enable = true; if (pmlmepriv->htpriv.ht_option) { pmlmeinfo->WMM_enable = true; pmlmeinfo->HT_enable = true; update_hw_ht_param(padapter); } /* setting only at first time */ if (pmlmepriv->cur_network.join_res != true) { /* WEP Key will be set before this function, do not * clear CAM. */ if ((psecuritypriv->dot11PrivacyAlgrthm != _WEP40_) && (psecuritypriv->dot11PrivacyAlgrthm != _WEP104_)) flush_all_cam_entry(padapter); /* clear CAM */ } /* set MSR to AP_Mode */ Set_MSR(padapter, _HW_STATE_AP_); /* Set BSSID REG */ rtw_hal_set_hwreg(padapter, HW_VAR_BSSID, pnetwork->MacAddress); /* Set EDCA param reg */ acparm = 0x002F3217; /* VO */ rtw_hal_set_hwreg(padapter, HW_VAR_AC_PARAM_VO, (u8 *)(&acparm)); acparm = 0x005E4317; /* VI */ rtw_hal_set_hwreg(padapter, HW_VAR_AC_PARAM_VI, (u8 *)(&acparm)); acparm = 0x005ea42b; rtw_hal_set_hwreg(padapter, HW_VAR_AC_PARAM_BE, (u8 *)(&acparm)); acparm = 0x0000A444; /* BK */ rtw_hal_set_hwreg(padapter, HW_VAR_AC_PARAM_BK, (u8 *)(&acparm)); /* Set Security */ val8 = (psecuritypriv->dot11AuthAlgrthm == dot11AuthAlgrthm_8021X) ? 0xcc : 0xcf; rtw_hal_set_hwreg(padapter, HW_VAR_SEC_CFG, (u8 *)(&val8)); /* Beacon Control related register */ rtw_hal_set_hwreg(padapter, HW_VAR_BEACON_INTERVAL, (u8 *)(&bcn_interval)); UpdateBrateTbl(padapter, pnetwork->SupportedRates); rtw_hal_set_hwreg(padapter, HW_VAR_BASIC_RATE, pnetwork->SupportedRates); if (!pmlmepriv->cur_network.join_res) { /* setting only at first time */ /* turn on all dynamic functions */ Switch_DM_Func(padapter, DYNAMIC_ALL_FUNC_ENABLE, true); } /* set channel, bwmode */ p = rtw_get_ie((pnetwork->ies + sizeof(struct ndis_802_11_fixed_ie)), _HT_ADD_INFO_IE_, &ie_len, (pnetwork->ie_length - sizeof(struct ndis_802_11_fixed_ie))); if (p && ie_len) { pht_info = (struct HT_info_element *)(p + 2); if ((pregpriv->cbw40_enable) && (pht_info->infos[0] & BIT(2))) { /* switch to the 40M Hz mode */ cur_bwmode = HT_CHANNEL_WIDTH_40; switch (pht_info->infos[0] & 0x3) { case 1: cur_ch_offset = HAL_PRIME_CHNL_OFFSET_LOWER; break; case 3: cur_ch_offset = HAL_PRIME_CHNL_OFFSET_UPPER; break; default: cur_ch_offset = HAL_PRIME_CHNL_OFFSET_DONT_CARE; break; } } } /* TODO: need to judge the phy parameters on concurrent * mode for single phy */ set_channel_bwmode(padapter, cur_channel, cur_ch_offset, cur_bwmode); DBG_88E("CH =%d, BW =%d, offset =%d\n", cur_channel, cur_bwmode, cur_ch_offset); /* */ pmlmeext->cur_channel = cur_channel; pmlmeext->cur_bwmode = cur_bwmode; pmlmeext->cur_ch_offset = cur_ch_offset; pmlmeext->cur_wireless_mode = pmlmepriv->cur_network.network_type; /* update cur_wireless_mode */ update_wireless_mode(padapter); /* update capability after cur_wireless_mode updated */ update_capinfo(padapter, rtw_get_capability((struct wlan_bssid_ex *)pnetwork)); /* let pnetwork_mlmeext == pnetwork_mlme. */ memcpy(pnetwork_mlmeext, pnetwork, pnetwork->Length); if (pmlmeext->bstart_bss) { update_beacon(padapter, _TIM_IE_, NULL, false); /* issue beacon frame */ if (send_beacon(padapter) == _FAIL) DBG_88E("send_beacon, fail!\n"); } /* update bc/mc sta_info */ update_bmc_sta(padapter); }
/* called periodically based on timer interrupts; write beacons to disk * file, time out any old stale beacons, and send an eth_beacon out via * the cat-5 connection. */ void eth_util_interrupt() { eth_util_interrupt_no_send(); send_beacon(); }