/************************************************************ * Module init procedure. ************************************************************/ static int __init goose_init(void) { printk("--------------------------------------\n"); printk("GOOSE: Stand by.\n"); printk("GOOSE: initiating proc file systems.\n"); if (proc_fs_init() != 0) { printk("GOOSE: Fatal error in initializing proc_fs!\n"); return -1; } printk("GOOSE: initiating netlink interface.\n"); if (netlink_init() != 0) { printk("GOOSE: Fatal error in initializing netlink!\n"); return -1; } /* initialize default dev*/ def_dev = dev_get_by_name(&init_net, buf_proc_def_dev); if (def_dev == NULL) { printk("GOOSE: Can not find %s, choose another device.\n", buf_proc_def_dev); } /* register GOOSE protocol */ dev_add_pack(&goose_packet_type); /* kernel_thread(daemon, NULL, 0); */ return 0; }
wrapd_hdl_t * wrapd_conn_to_global_wpa_s(const char *ifname, const char *confname, int isolation, int timer) { struct wrap_demon *aptr; char *realname = (void *)ifname; struct netlink_config *cfg; if (!realname) return NULL; aptr = os_zalloc(sizeof(*aptr)); if (!aptr) return NULL; aptr->ioctl_sock = socket(PF_INET, SOCK_DGRAM, 0); if (aptr->ioctl_sock < 0) { wrapd_printf("socket[PF_INET,SOCK_DGRAM]"); return NULL; } aptr->global = wpa_ctrl_open(realname); if (!aptr->global) { close(aptr->ioctl_sock); os_free(aptr); wrapd_printf("Fail to connect global wpa_s"); return NULL; } cfg = os_zalloc(sizeof(*cfg)); if (cfg == NULL) { close(aptr->ioctl_sock); os_free(aptr); return NULL; } cfg->ctx = aptr; cfg->newlink_cb = wrapd_event_rtm_newlink; aptr->netlink = netlink_init(cfg); if (aptr->netlink == NULL) { close(aptr->ioctl_sock); os_free(cfg); os_free(aptr); return NULL; } if (confname) aptr->wpa_conf_file = os_strdup(confname); if (isolation == 1) aptr->do_isolation = 1; else aptr->do_isolation = 0; if (timer == 1) aptr->do_timer = 1; else aptr->do_timer = 0; return (void *) aptr; }
/*---------------------------------------------------------------- * main * * wland entry point. * * Arguments: * argc number of command line arguments * argv array of argument strings * * Returns: * 0 - success * ~0 - failure ----------------------------------------------------------------*/ int main(int argc, char *argv[]) { int errflg; int optch; errflg = 0; /* Set Globals */ msgfp = NULL; nlfd = -1; user_process = 0; while ((optch = getopt(argc, argv, "Vvd:u")) != -1) { switch (optch) { case 'V': case 'v': fprintf(stderr, "wland version %s\n", WLAN_RELEASE); return 0; break; case 'd': wland_path = strdup(optarg); break; case 'u': user_process = 1; break; default: errflg = 1; break; } } if (errflg || (optind < argc)) { usage(argv[0]); exit(1); } if ( chdir(wland_path) < 0 ) { fprintf(stderr, "wland: ERROR changing to directory %s\n", wland_path); exit(1); } if ( !user_process ) { if ( !(daemon_init()) ) { exit(1); } } if ( !(netlink_init()) ) { exit(1); } process_messages(); return 0; }
void kct_netlink_init_comm(void) { unsigned int connect_try = KCT_MAX_CONNECT_TRY; while (connect_try-- != 0) { /* Try to connect */ if ((sock_nl_fd = netlink_init()) != -1) break; LOGE("%s: Delaying kct_netlink_init_comm\n", __FUNCTION__); /* Wait */ sleep(KCT_CONNECT_RETRY_TIME_S); } }
static int rtl871x_wireless_event_init(struct rtl871x_driver_data *drv) { struct netlink_config *cfg; cfg = os_zalloc(sizeof(*cfg)); if (cfg == NULL) return -1; cfg->ctx = drv; cfg->newlink_cb = rtl871x_wireless_event_rtm_newlink; drv->netlink = netlink_init(cfg); if (drv->netlink == NULL) { os_free(cfg); return -1; } return 0; }
static int hostap_wireless_event_init(struct hostap_driver_data *drv) { struct netlink_config *cfg; hostap_get_we_version(drv); cfg = os_zalloc(sizeof(*cfg)); if (cfg == NULL) return -1; cfg->ctx = drv; cfg->newlink_cb = hostapd_wireless_event_rtm_newlink; drv->netlink = netlink_init(cfg); if (drv->netlink == NULL) { os_free(cfg); return -1; } return 0; }
static int init_matchnf(void) { if (match_sys_init() != 0) { printk("match system init was failed!\n"); return -1; } if (netlink_init() != 0) { printk("netlink init was failed!\n"); } fops_init_module(); ops_nfhk_li.hook = hook_match_packet_li; ops_nfhk_li.owner = THIS_MODULE, ops_nfhk_li.hooknum = NF_INET_LOCAL_IN; ops_nfhk_li.pf = PF_INET; ops_nfhk_li.priority= NF_IP_PRI_FIRST; if (nf_register_hook(&ops_nfhk_li) != 0) { printk("register LOCAL_IN hook was failed!\n"); return -1; } ops_nfhk_lo.hook = hook_match_packet_lo; ops_nfhk_li.owner = THIS_MODULE, ops_nfhk_lo.hooknum = NF_INET_LOCAL_OUT; ops_nfhk_lo.pf = PF_INET; ops_nfhk_lo.priority= NF_IP_PRI_FIRST; if (nf_register_hook(&ops_nfhk_lo) != 0) { printk("register LOCAL_OUT hook was failed!\n"); return -1; } printk("Init init_matchnf!\n"); return 0; }
int main(int argc, char *argv[]) { int c; int exitcode = 0; char *mesh_id; FD_ZERO(&rd_sock_set); FD_ZERO(&wr_sock_set); int max_fds = 0; for (;;) { c = getopt(argc, argv, "Bi:s:"); if (c < 0) break; switch (c) { case 'B': /* TODO: background operation */ break; case 'i': ifname = optarg; break; case 's': mesh_id = optarg; break; default: usage(); goto out; } } if (ifname == NULL) { usage(); exitcode = -EINVAL; goto out; } if (netlink_init(event_handler)) { exitcode = -ESOCKTNOSUPPORT; goto out; } memset(bogus_ie, 0, sizeof(bogus_ie)); /* Vendor specific */ bogus_ie[0] = 221; /* nl80211 will check that this is an information element by inspecting its length field. So this bogus ie should at least have a correct length, which we set below. */ bogus_ie[1] = sizeof(bogus_ie) - 2; snprintf(&bogus_ie[5], sizeof(bogus_ie) - 2, "yay!"); exitcode = join_mesh(ifname, mesh_id, strlen(mesh_id), bogus_ie, sizeof(bogus_ie)); if (exitcode) return exitcode; exitcode = reroute_path_selection_frames(ifname); if (exitcode) return exitcode; wait_on_sockets(); /* TODO: Remove beacon on exit. In order to remove the beacon, we need to get the beacon from o11s, delete it, and then add it again without a tail. This requires the command NL80211_CMD_GET_BEACON to be implemented. */ out: return exitcode; }
int main (int argc, char **argv) { int c; int start_event = 0; bool foreground = false; while (1) { c = getopt_long(argc, argv, "fhbgv", long_opts, NULL); if (c == EOF) break; switch (c) { case 'b': start_event |= START_BOOT; break; case 'f': foreground = true; break; case 'g': start_event |= START_GET_RPC_METHOD; break; case 'h': print_help(); exit(EXIT_SUCCESS); case 'v': print_version(); exit(EXIT_SUCCESS); default: print_help(); exit(EXIT_FAILURE); } } log_message(NAME, L_DEBUG, "daemon started\n"); setlocale(LC_CTYPE, ""); umask(0037); if (getuid() != 0) { D("run %s as root\n", NAME); exit(EXIT_FAILURE); } /* run early cwmp initialization */ cwmp = calloc(1, sizeof(struct cwmp_internal)); if (!cwmp) return -1; INIT_LIST_HEAD(&cwmp->events); INIT_LIST_HEAD(&cwmp->notifications); INIT_LIST_HEAD(&cwmp->downloads); INIT_LIST_HEAD(&cwmp->scheduled_informs); uloop_init(); backup_init(); config_load(); cwmp_init_deviceid(); if (start_event & START_BOOT) { cwmp_add_event(EVENT_BOOT, NULL, 0, EVENT_BACKUP); cwmp_add_inform_timer(); } if (start_event & START_GET_RPC_METHOD) { cwmp->get_rpc_methods = true; cwmp_add_event(EVENT_PERIODIC, NULL, 0, EVENT_BACKUP); cwmp_add_inform_timer(); } if (netlink_init()) { D("netlink initialization failed\n"); exit(EXIT_FAILURE); } if (ubus_init()) D("ubus initialization failed\n"); http_server_init(); pid_t pid, sid; if (!foreground) { pid = fork(); if (pid < 0) exit(EXIT_FAILURE); if (pid > 0) exit(EXIT_SUCCESS); sid = setsid(); if (sid < 0) { D("setsid() returned error\n"); exit(EXIT_FAILURE); } char *directory = "/"; if ((chdir(directory)) < 0) { D("chdir() returned error\n"); exit(EXIT_FAILURE); } } log_message(NAME, L_DEBUG, "entering main loop\n"); uloop_run(); ubus_exit(); uloop_done(); http_client_exit(); xml_exit(); config_exit(); cwmp_free_deviceid(); free(cwmp); closelog(); log_message(NAME, L_DEBUG, "exiting\n"); return 0; }
int main (int argc, char **argv) { Interface_init(); s_t* st2=(s_t*)(Instance[1].gm->mem_ref.pointer); st2->port=38800; char c; s32 i, j; int new_omg_model; // goto ocg in oai_emulation.info. // pointers signal buffers (s = transmit, r,r0 = receive) double **s_re[NINST], **s_im[NINST], **r_re[NINST], **r_im[NINST], **r_re0, **r_im0; double **r_re0_d[8][3], **r_im0_d[8][3], **r_re0_u[3][8],**r_im0_u[3][8]; // double **s_re, **s_im, **r_re, **r_im, **r_re0, **r_im0; double forgetting_factor=0; int map1,map2; double **ShaF= NULL; // Framing variables s32 slot, last_slot, next_slot; // variables/flags which are set by user on command-line double snr_dB, sinr_dB; u8 set_snr=0,set_sinr=0; u8 cooperation_flag; // for cooperative communication u8 target_dl_mcs = 4; u8 target_ul_mcs = 2; u8 rate_adaptation_flag; u8 abstraction_flag = 0, ethernet_flag = 0; u16 Nid_cell = 0; s32 UE_id, eNB_id, ret; // time calibration for soft realtime mode struct timespec time_spec; unsigned long time_last, time_now; int td, td_avg, sleep_time_us; char *g_log_level = "trace"; // by default global log level is set to trace lte_subframe_t direction; #ifdef XFORMS FD_phy_procedures_sim *form[NUMBER_OF_eNB_MAX][NUMBER_OF_UE_MAX]; char title[255]; #endif LTE_DL_FRAME_PARMS *frame_parms; FILE *UE_stats[NUMBER_OF_UE_MAX], *eNB_stats; char UE_stats_filename[255]; int len; #ifdef ICIC remove ("dci.txt"); #endif //time_t t0,t1; clock_t start, stop; // Added for PHY abstraction Node_list ue_node_list = NULL; Node_list enb_node_list = NULL; //default parameters target_dl_mcs = 0; rate_adaptation_flag = 0; oai_emulation.info.n_frames = 0xffff;//1024; //100; oai_emulation.info.n_frames_flag = 0;//fixme snr_dB = 30; cooperation_flag = 0; // default value 0 for no cooperation, 1 for Delay diversity, 2 for Distributed Alamouti init_oai_emulation(); // to initialize everything !!! // get command-line options while ((c = getopt (argc, argv, "haePToFt:C:N:k:x:m:rn:s:S:f:z:u:b:c:M:p:g:l:d:U:B:R:E:")) != -1) { switch (c) { case 'F': // set FDD oai_emulation.info.frame_type = 0; break; case 'C': oai_emulation.info.tdd_config = atoi (optarg); if (oai_emulation.info.tdd_config > 6) { msg ("Illegal tdd_config %d (should be 0-6)\n", oai_emulation.info.tdd_config); exit (-1); } break; case 'R': oai_emulation.info.N_RB_DL = atoi (optarg); if ((oai_emulation.info.N_RB_DL != 6) && (oai_emulation.info.N_RB_DL != 15) && (oai_emulation.info.N_RB_DL != 25) && (oai_emulation.info.N_RB_DL != 50) && (oai_emulation.info.N_RB_DL != 75) && (oai_emulation.info.N_RB_DL != 100)) { msg ("Illegal N_RB_DL %d (should be one of 6,15,25,50,75,100)\n", oai_emulation.info.N_RB_DL); exit (-1); } case 'N': Nid_cell = atoi (optarg); if (Nid_cell > 503) { msg ("Illegal Nid_cell %d (should be 0 ... 503)\n", Nid_cell); exit(-1); } break; case 'h': help (); exit (1); case 'x': oai_emulation.info.transmission_mode = atoi (optarg); if ((oai_emulation.info.transmission_mode != 1) && (oai_emulation.info.transmission_mode != 2) && (oai_emulation.info.transmission_mode != 5) && (oai_emulation.info.transmission_mode != 6)) { msg("Unsupported transmission mode %d\n",oai_emulation.info.transmission_mode); exit(-1); } break; case 'm': target_dl_mcs = atoi (optarg); break; case 'r': rate_adaptation_flag = 1; break; case 'n': oai_emulation.info.n_frames = atoi (optarg); //n_frames = (n_frames >1024) ? 1024: n_frames; // adjust the n_frames if higher that 1024 oai_emulation.info.n_frames_flag = 1; break; case 's': snr_dB = atoi (optarg); set_snr = 1; oai_emulation.info.ocm_enabled=0; break; case 'S': sinr_dB = atoi (optarg); set_sinr = 1; oai_emulation.info.ocm_enabled=0; break; case 'k': //ricean_factor = atof (optarg); printf("[SIM] Option k is no longer supported on the command line. Please specify your channel model in the xml template\n"); exit(-1); break; case 't': //Td = atof (optarg); printf("[SIM] Option t is no longer supported on the command line. Please specify your channel model in the xml template\n"); exit(-1); break; case 'f': forgetting_factor = atof (optarg); break; case 'z': cooperation_flag = atoi (optarg); break; case 'u': oai_emulation.info.nb_ue_local = atoi (optarg); break; case 'b': oai_emulation.info.nb_enb_local = atoi (optarg); break; case 'a': abstraction_flag = 1; break; case 'p': oai_emulation.info.nb_master = atoi (optarg); break; case 'M': abstraction_flag = 1; ethernet_flag = 1; oai_emulation.info.ethernet_id = atoi (optarg); oai_emulation.info.master_id = oai_emulation.info.ethernet_id; oai_emulation.info.ethernet_flag = 1; break; case 'e': oai_emulation.info.extended_prefix_flag = 1; break; case 'l': g_log_level = optarg; break; case 'c': strcpy(oai_emulation.info.local_server, optarg); oai_emulation.info.ocg_enabled=1; break; case 'g': oai_emulation.info.multicast_group = atoi (optarg); break; case 'B': oai_emulation.info.omg_model_enb = atoi (optarg); break; case 'U': oai_emulation.info.omg_model_ue = atoi (optarg); break; case 'T': oai_emulation.info.otg_enabled = 1; break; case 'P': oai_emulation.info.opt_enabled = 1; break; case 'E': oai_emulation.info.seed = atoi (optarg); break; default: help (); exit (-1); break; } } // configure oaisim with OCG oaisim_config(g_log_level); // config OMG and OCG, OPT, OTG, OLG if (oai_emulation.info.nb_ue_local > NUMBER_OF_UE_MAX ) { printf ("Enter fewer than %d UEs for the moment or change the NUMBER_OF_UE_MAX\n", NUMBER_OF_UE_MAX); exit (-1); } if (oai_emulation.info.nb_enb_local > NUMBER_OF_eNB_MAX) { printf ("Enter fewer than %d eNBs for the moment or change the NUMBER_OF_UE_MAX\n", NUMBER_OF_eNB_MAX); exit (-1); } // fix ethernet and abstraction with RRC_CELLULAR Flag #ifdef RRC_CELLULAR abstraction_flag = 1; ethernet_flag = 0; #endif if (set_sinr == 0) sinr_dB = snr_dB - 20; // setup ntedevice interface (netlink socket) #ifndef CYGWIN ret = netlink_init (); #endif if (ethernet_flag == 1) { oai_emulation.info.master[oai_emulation.info.master_id].nb_ue = oai_emulation.info.nb_ue_local; oai_emulation.info.master[oai_emulation.info.master_id].nb_enb = oai_emulation.info.nb_enb_local; if (!oai_emulation.info.master_id) oai_emulation.info.is_primary_master = 1; j = 1; for (i = 0; i < oai_emulation.info.nb_master; i++) { if (i != oai_emulation.info.master_id) oai_emulation.info.master_list = oai_emulation.info.master_list + j; LOG_I (EMU, "Index of master id i=%d MASTER_LIST %d\n", i, oai_emulation.info.master_list); j *= 2; } LOG_I (EMU, " Total number of master %d my master id %d\n", oai_emulation.info.nb_master, oai_emulation.info.master_id); #ifdef LINUX init_bypass (); #endif while (emu_tx_status != SYNCED_TRANSPORT) { LOG_I (EMU, " Waiting for EMU Transport to be synced\n"); emu_transport_sync (); //emulation_tx_rx(); } } // ethernet flag NB_UE_INST = oai_emulation.info.nb_ue_local + oai_emulation.info.nb_ue_remote; NB_eNB_INST = oai_emulation.info.nb_enb_local + oai_emulation.info.nb_enb_remote; #ifndef NAS_NETLINK for (UE_id=0;UE_id<NB_UE_INST;UE_id++) { sprintf(UE_stats_filename,"UE_stats%d.txt",UE_id); UE_stats[UE_id] = fopen (UE_stats_filename, "w"); } eNB_stats = fopen ("eNB_stats.txt", "w"); printf ("UE_stats=%p, eNB_stats=%p\n", UE_stats, eNB_stats); #endif LOG_I(EMU, "total number of UE %d (local %d, remote %d) \n", NB_UE_INST,oai_emulation.info.nb_ue_local,oai_emulation.info.nb_ue_remote); LOG_I(EMU, "Total number of eNB %d (local %d, remote %d) \n", NB_eNB_INST,oai_emulation.info.nb_enb_local,oai_emulation.info.nb_enb_remote); printf("Running with frame_type %d, Nid_cell %d, N_RB_DL %d, EP %d, mode %d, target dl_mcs %d, rate adaptation %d, nframes %d, abstraction %d\n", 1+oai_emulation.info.frame_type, Nid_cell, oai_emulation.info.N_RB_DL, oai_emulation.info.extended_prefix_flag, oai_emulation.info.transmission_mode,target_dl_mcs,rate_adaptation_flag,oai_emulation.info.n_frames,abstraction_flag); // init_lte_vars (&frame_parms, oai_emulation.info.frame_type, oai_emulation.info.tdd_config, oai_emulation.info.extended_prefix_flag,oai_emulation.info.N_RB_DL, Nid_cell, cooperation_flag, oai_emulation.info.transmission_mode, abstraction_flag); init_frame_params (&frame_parms, oai_emulation.info.frame_type, oai_emulation.info.tdd_config, oai_emulation.info.extended_prefix_flag,oai_emulation.info.N_RB_DL, Nid_cell, cooperation_flag, oai_emulation.info.transmission_mode, abstraction_flag); printf ("Nid_cell %d\n", frame_parms->Nid_cell); /* Added for PHY abstraction */ if (abstraction_flag) get_beta_map(); for (eNB_id = 0; eNB_id < NB_eNB_INST; eNB_id++) { enb_data[eNB_id] = (node_desc_t *)malloc(sizeof(node_desc_t)); init_enb(enb_data[eNB_id],oai_emulation.environment_system_config.antenna.eNB_antenna); } for (UE_id = 0; UE_id < NB_UE_INST; UE_id++) { ue_data[UE_id] = (node_desc_t *)malloc(sizeof(node_desc_t)); init_ue(ue_data[UE_id],oai_emulation.environment_system_config.antenna.UE_antenna); } // init SF map here!!! map1 =(int)oai_emulation.topology_config.area.x_km; map2 =(int)oai_emulation.topology_config.area.y_km; //ShaF = createMat(map1,map2); -> memory is allocated within init_SF ShaF = init_SF(map1,map2,DECOR_DIST,SF_VAR); // size of area to generate shadow fading map printf("Simulation area x=%f, y=%f\n", oai_emulation.topology_config.area.x_km, oai_emulation.topology_config.area.y_km); if (abstraction_flag == 0){ int ci; int ji=0; for(ci=0;ci<NB_eNB_INST;ci++) { init_channel_mmap_channel(10+ji,frame_parms, &(s_re[ci]), &(s_im[ci]), &(r_re[ci]), &(r_im[ci]), &(r_re0), &(r_im0)); ji++; //printf("ci %d\n",ci); } ji=0; for(ci=NB_eNB_INST;ci<(NB_eNB_INST+NB_UE_INST);ci++) { init_channel_mmap_channel(20+ji,frame_parms, &(s_re[ci]), &(s_im[ci]), &(r_re[ci]), &(r_im[ci]), &(r_re0), &(r_im0)); ji++; //printf("ci %d\n",ci); } } for (eNB_id = 0; eNB_id < NB_eNB_INST; eNB_id++) { for (UE_id = 0; UE_id < NB_UE_INST; UE_id++) { init_rre(frame_parms,&(r_re0_u[eNB_id][UE_id]),&(r_im0_u[eNB_id][UE_id])); init_rre(frame_parms,&(r_re0_d[UE_id][eNB_id]),&(r_im0_d[UE_id][eNB_id])); } } // printf("r_re0 %lf , r_im0 %lf\n",r_re0_u[0][0][0][0],r_im0_u[0][0][0][0]); // // r_im0_u[0][0][0][0]=100; // // printf("r_re0 %lf , r_im0 %lf\n",r_re0_u[0][0][0][0],r_im0_u[0][0][0][0]); // // // clean_param((r_re0_u[0][0]),(r_im0_u[0][0]),frame_parms); // // printf("r_re0 %lf , r_im0 %lf\n",r_re0_u[0][0][0][0],r_im0_u[0][0][0][0]); for (eNB_id = 0; eNB_id < NB_eNB_INST; eNB_id++) { for (UE_id = 0; UE_id < NB_UE_INST; UE_id++) { #ifdef DEBUG_SIM printf ("[SIM] Initializing channel from eNB %d to UE %d\n", eNB_id, UE_id); #endif eNB2UE[eNB_id][UE_id] = new_channel_desc_scm(2, 2, map_str_to_int(small_scale_names, oai_emulation.environment_system_config.fading.small_scale.selected_option), oai_emulation.environment_system_config.system_bandwidth_MB, forgetting_factor, 0, 0); UE2eNB[UE_id][eNB_id] = new_channel_desc_scm(2, 2, map_str_to_int(small_scale_names, oai_emulation.environment_system_config.fading.small_scale.selected_option), oai_emulation.environment_system_config.system_bandwidth_MB, forgetting_factor, 0, 0); } } randominit (0); set_taus_seed (0); number_of_cards = 1; openair_daq_vars.rx_rf_mode = 1; openair_daq_vars.tdd = 1; openair_daq_vars.rx_gain_mode = DAQ_AGC_ON; openair_daq_vars.dlsch_transmission_mode = oai_emulation.info.transmission_mode; openair_daq_vars.target_ue_dl_mcs = target_dl_mcs; openair_daq_vars.target_ue_ul_mcs = target_ul_mcs; openair_daq_vars.dlsch_rate_adaptation = rate_adaptation_flag; openair_daq_vars.ue_ul_nb_rb = 2; #ifdef XFORMS fl_initialize (&argc, argv, NULL, 0, 0); for (UE_id = 0; UE_id < NB_UE_INST; UE_id++) for (eNB_id = 0; eNB_id < NB_eNB_INST; eNB_id++) { form[eNB_id][UE_id] = create_form_phy_procedures_sim (); sprintf (title, "LTE SIM UE %d eNB %d", UE_id, eNB_id); fl_show_form (form[eNB_id][UE_id]->phy_procedures_sim, FL_PLACE_HOTSPOT, FL_FULLBORDER, title); } #endif // time calibration for OAI clock_gettime (CLOCK_REALTIME, &time_spec); time_now = (unsigned long) time_spec.tv_nsec; td_avg = 0; sleep_time_us = SLEEP_STEP_US; td_avg = TARGET_SF_TIME_NS; // s_t* st2=(s_t*)(Instance[1].gm->mem_ref.pointer); st2->Exec_FLAG=0; int count; IntInitAll(); Soc_t* this = (Soc_t*)(obj_inst[0].ptr->mem_ref.pointer); fd_set read_ibits; fd_set write_ibits; int n; struct timeval tvp ; tvp.tv_sec=10; tvp.tv_usec=0; FD_ZERO(&read_ibits); FD_SET(this->m_io_sync.io_sync_entries->fd_read, &read_ibits); ch_thread *e2u_t[NB_eNB_INST][NB_UE_INST]; ch_thread *u2e_t[NB_UE_INST][NB_eNB_INST]; for(eNB_id=0;eNB_id<NB_eNB_INST;eNB_id++){ for(UE_id=0;UE_id<NB_UE_INST;UE_id++){ e2u_t[eNB_id][UE_id]=(ch_thread*)calloc(1,sizeof(ch_thread)); }} for(UE_id=0;UE_id<NB_UE_INST;UE_id++){ for(eNB_id=0;eNB_id<NB_eNB_INST;eNB_id++){ u2e_t[UE_id][eNB_id]=(ch_thread*)calloc(1,sizeof(ch_thread)); }} pthread_t thread,thread2; pthread_t cthr_u[NB_eNB_INST][NB_UE_INST]; pthread_t cthr_d[NB_UE_INST][NB_eNB_INST]; for (UE_id = oai_emulation.info.first_ue_local; UE_id < (oai_emulation.info.first_ue_local + oai_emulation.info.nb_ue_local); UE_id++){ for (eNB_id=oai_emulation.info.first_enb_local;eNB_id<(oai_emulation.info.first_enb_local+oai_emulation.info.nb_enb_local);eNB_id++) { u2e_t[UE_id][eNB_id]->eNB_id=eNB_id; u2e_t[UE_id][eNB_id]->UE_id=UE_id; u2e_t[UE_id][eNB_id]->r_re0=r_re0_d[UE_id][eNB_id]; u2e_t[UE_id][eNB_id]->r_im0=r_im0_d[UE_id][eNB_id]; u2e_t[UE_id][eNB_id]->r_re=r_re[NB_eNB_INST+UE_id]; u2e_t[UE_id][eNB_id]->r_im=r_im[NB_eNB_INST+UE_id]; u2e_t[UE_id][eNB_id]->s_im=s_im[eNB_id]; u2e_t[UE_id][eNB_id]->s_re=s_re[eNB_id]; u2e_t[UE_id][eNB_id]->eNB2UE=eNB2UE[eNB_id][UE_id]; u2e_t[UE_id][eNB_id]->UE2eNB=UE2eNB[UE_id][eNB_id]; u2e_t[UE_id][eNB_id]->enb_data=enb_data[eNB_id]; u2e_t[UE_id][eNB_id]->ue_data=ue_data[UE_id]; u2e_t[UE_id][eNB_id]->next_slot=&next_slot; u2e_t[UE_id][eNB_id]->abstraction_flag=&abstraction_flag; u2e_t[UE_id][eNB_id]->frame_parms=frame_parms; pthread_create (&cthr_d[UE_id][eNB_id], NULL, do_DL_sig_channel_T,(void*)(u2e_t[UE_id][eNB_id])); } } int sock; int port=(35000+(10+eNB_id)+(20+UE_id)); port=35010; sock = openairInetCreateSocket(SOCK_DGRAM,IPPROTO_UDP,"127.0.0.1",port); // int n; // fd_set read_ibits; // fd_set write_ibits; // struct timeval tvp = { 0, 0 }; FD_ZERO(&read_ibits); FD_SET(sock,&read_ibits); n = openairSelect(sock+1, &read_ibits, NULL, NULL, NULL); printf("Waiting is over\n"); FD_ISSET(sock, &read_ibits); for (mac_xface->frame=0; mac_xface->frame<oai_emulation.info.n_frames; mac_xface->frame++) { int dir_flag=0; printf("=============== Frame Number %d ============= \n ",mac_xface->frame); /* // Handling the cooperation Flag if (cooperation_flag == 2) { if ((PHY_vars_eNB_g[0]->eNB_UE_stats[0].mode == PUSCH) && (PHY_vars_eNB_g[0]->eNB_UE_stats[1].mode == PUSCH)) PHY_vars_eNB_g[0]->cooperation_flag = 2; } */ // for dubugging the frame counter update_nodes(oai_emulation.info.time); enb_node_list = get_current_positions(oai_emulation.info.omg_model_enb, eNB, oai_emulation.info.time); ue_node_list = get_current_positions(oai_emulation.info.omg_model_ue, UE, oai_emulation.info.time); // update the position of all the nodes (eNB/CH, and UE/MR) every frame if (((int)oai_emulation.info.time % 10) == 0 ) { display_node_list(enb_node_list); display_node_list(ue_node_list); if (oai_emulation.info.omg_model_ue >= MAX_NUM_MOB_TYPES){ // mix mobility model for(UE_id=oai_emulation.info.first_ue_local; UE_id<(oai_emulation.info.first_ue_local+oai_emulation.info.nb_ue_local);UE_id++){ new_omg_model = randomGen(STATIC, MAX_NUM_MOB_TYPES); LOG_D(OMG, "[UE] Node of ID %d is changing mobility generator ->%d \n", UE_id, new_omg_model); // reset the mobility model for a specific node set_new_mob_type (UE_id, UE, new_omg_model, oai_emulation.info.time); } } if (oai_emulation.info.omg_model_enb >= MAX_NUM_MOB_TYPES) { // mix mobility model for (eNB_id = oai_emulation.info.first_enb_local; eNB_id < (oai_emulation.info.first_enb_local + oai_emulation.info.nb_enb_local); eNB_id++) { new_omg_model = randomGen (STATIC, MAX_NUM_MOB_TYPES); LOG_D (OMG, "[eNB] Node of ID %d is changing mobility generator ->%d \n", UE_id, new_omg_model); // reset the mobility model for a specific node set_new_mob_type (eNB_id, eNB, new_omg_model, oai_emulation.info.time); } } } #ifdef DEBUG_OMG if ((((int) oai_emulation.info.time) % 100) == 0) { for (UE_id = oai_emulation.info.first_ue_local; UE_id < (oai_emulation.info.first_ue_local + oai_emulation.info.nb_ue_local); UE_id++) { get_node_position (UE, UE_id); } } #endif if (oai_emulation.info.n_frames_flag == 0){ // if n_frames not set by the user then let the emulation run to infinity mac_xface->frame %=(oai_emulation.info.n_frames-1); // set the emulation time based on 1ms subframe number oai_emulation.info.time += 0.01; // emu time in s } else { // user set the number of frames for the emulation // let the time go faster to see the effect of mobility oai_emulation.info.time += 0.1; } /* check if the openair channel model is activated used for PHY abstraction */ /* if ((oai_emulation.info.ocm_enabled == 1)&& (ethernet_flag == 0 )) { extract_position(enb_node_list, enb_data, NB_eNB_INST); extract_position(ue_node_list, ue_data, NB_UE_INST); for (eNB_id = 0; eNB_id < NB_eNB_INST; eNB_id++) { for (UE_id = 0; UE_id < NB_UE_INST; UE_id++) { calc_path_loss (enb_data[eNB_id], ue_data[UE_id], eNB2UE[eNB_id][UE_id], oai_emulation.environment_system_config,ShaF[(int)ue_data[UE_id]->x][(int)ue_data[UE_id]->y]); UE2eNB[UE_id][eNB_id]->path_loss_dB = eNB2UE[eNB_id][UE_id]->path_loss_dB; printf("[CHANNEL_SIM] Pathloss bw enB %d at (%f,%f) and UE%d at (%f,%f) is %f (ShaF %f)\n", eNB_id,enb_data[eNB_id]->x,enb_data[eNB_id]->y,UE_id,ue_data[UE_id]->x,ue_data[UE_id]->y, eNB2UE[eNB_id][UE_id]->path_loss_dB, ShaF[(int)ue_data[UE_id]->x][(int)ue_data[UE_id]->y]); } } } */ // else { for (eNB_id = 0; eNB_id < NB_eNB_INST; eNB_id++) { for (UE_id = 0; UE_id < NB_UE_INST; UE_id++) { eNB2UE[eNB_id][UE_id]->path_loss_dB = -105 + snr_dB; //UE2eNB[UE_id][eNB_id]->path_loss_dB = -105 + snr_dB; if (eNB_id == (UE_id % NB_eNB_INST)) UE2eNB[UE_id][eNB_id]->path_loss_dB = -105 + snr_dB - 10; else UE2eNB[UE_id][eNB_id]->path_loss_dB = -105 + sinr_dB - 10; #ifdef DEBUG_SIM printf("[SIM] Path loss from eNB %d to UE %d => %f dB\n",eNB_id,UE_id,eNB2UE[eNB_id][UE_id]->path_loss_dB); printf("[SIM] Path loss from UE %d to eNB %d => %f dB\n",UE_id,eNB_id,UE2eNB[UE_id][eNB_id]->path_loss_dB); #endif } } // } else st2->EResp_FLAG=0; for (slot=0 ; slot<20 ; slot++) { printf("=============== Frame Number %d , Slot %d ============= \n ",mac_xface->frame,slot); last_slot = (slot - 1)%20; if (last_slot <0) last_slot+=20; next_slot = (slot + 1)%20; direction = subframe_select(frame_parms,next_slot>>1); if (direction == SF_DL) { dir_flag=1; } else if (direction == SF_UL) { dir_flag=2; } else {//it must be a special subframe if (next_slot%2==0) {//DL part dir_flag=1; } else {// UL part dir_flag=2; } } int count=0; if(dir_flag==1) { st2->EResp_FLAG=0; count=0; for (eNB_id=oai_emulation.info.first_enb_local;eNB_id<(oai_emulation.info.first_enb_local+oai_emulation.info.nb_enb_local);eNB_id++) { send_exec_msg(next_slot,last_slot,mac_xface->frame,mac_xface->frame,slot,0,38810+eNB_id); printf("Waiting for Exec Msg Complete \n"); // n = openairIoSyncCreateThread_2(&this->m_io_sync); } // for loop while(count<NB_eNB_INST){ n=trig_wait((void*)&this->m_io_sync); count++; } for (UE_id = oai_emulation.info.first_ue_local; UE_id < (oai_emulation.info.first_ue_local + oai_emulation.info.nb_ue_local); UE_id++){ for (eNB_id=oai_emulation.info.first_enb_local;eNB_id<(oai_emulation.info.first_enb_local+oai_emulation.info.nb_enb_local);eNB_id++) { //trigger message send_exec_msg(0,0,0,0,0,0,(35000+(10+eNB_id)+(20+UE_id))); } } usleep(5); // while(st2->EResp_FLAG<NB_eNB_INST) // { /* for (UE_id = oai_emulation.info.first_ue_local; UE_id < (oai_emulation.info.first_ue_local + oai_emulation.info.nb_ue_local); UE_id++){ for (eNB_id=oai_emulation.info.first_enb_local;eNB_id<(oai_emulation.info.first_enb_local+oai_emulation.info.nb_enb_local);eNB_id++) { u2e_t[UE_id][eNB_id]->eNB_id=eNB_id; u2e_t[UE_id][eNB_id]->UE_id=UE_id; u2e_t[UE_id][eNB_id]->r_re0=r_re0_d[UE_id][eNB_id]; u2e_t[UE_id][eNB_id]->r_im0=r_im0_d[UE_id][eNB_id]; u2e_t[UE_id][eNB_id]->r_re=r_re[NB_eNB_INST+UE_id]; u2e_t[UE_id][eNB_id]->r_im=r_im[NB_eNB_INST+UE_id]; u2e_t[UE_id][eNB_id]->s_im=s_im[eNB_id]; u2e_t[UE_id][eNB_id]->s_re=s_re[eNB_id]; u2e_t[UE_id][eNB_id]->eNB2UE=eNB2UE[eNB_id][UE_id]; u2e_t[UE_id][eNB_id]->UE2eNB=UE2eNB[UE_id][eNB_id]; u2e_t[UE_id][eNB_id]->enb_data=enb_data[eNB_id]; u2e_t[UE_id][eNB_id]->ue_data=ue_data[UE_id]; u2e_t[UE_id][eNB_id]->next_slot=&next_slot; u2e_t[UE_id][eNB_id]->abstraction_flag=&abstraction_flag; u2e_t[UE_id][eNB_id]->frame_parms=frame_parms; // pthread_create (&thread[eNB_id][UE_id], NULL, do_DL_sig_channel_T,(void*)cthread); pthread_create (&cthr_d[UE_id][eNB_id], NULL, do_DL_sig_channel_T,(void*)(u2e_t[UE_id][eNB_id])); // pthread_join(cthr_d[UE_id][eNB_id], NULL); // pthread_join(cthr_d[UE_id][eNB_id], NULL); // pthread_join(thread[eNB_id][UE_id], NULL); // do_DL_sig_channel(eNB_id,UE_id,r_re0,r_im0,r_re[NB_eNB_INST+UE_id],r_im[NB_eNB_INST+UE_id],s_re[eNB_id],s_im[eNB_id],eNB2UE,enb_data, ue_data,next_slot,abstraction_flag,frame_parms); // do_DL_sig_channel(eNB_id,UE_id,r_re0_d[UE_id][eNB_id],r_im0_d[UE_id][eNB_id],r_re[NB_eNB_INST+UE_id],r_im[NB_eNB_INST+UE_id],s_re[eNB_id],s_im[eNB_id],eNB2UE,enb_data, ue_data,next_slot,abstraction_flag,frame_parms); } } */ // //for (UE_id = oai_emulation.info.first_ue_local; UE_id < (oai_emulation.info.first_ue_local + oai_emulation.info.nb_ue_local); UE_id++){ //for (eNB_id=oai_emulation.info.first_enb_local;eNB_id<(oai_emulation.info.first_enb_local+oai_emulation.info.nb_enb_local);eNB_id++) { //pthread_join(cthr_d[UE_id][eNB_id], NULL); //} //} for (UE_id = oai_emulation.info.first_ue_local; UE_id < (oai_emulation.info.first_ue_local + oai_emulation.info.nb_ue_local); UE_id++){ clean_param(r_re[NB_eNB_INST+UE_id],r_im[NB_eNB_INST+UE_id],frame_parms); for (eNB_id=oai_emulation.info.first_enb_local;eNB_id<(oai_emulation.info.first_enb_local+oai_emulation.info.nb_enb_local);eNB_id++) { channel_add(r_re[NB_eNB_INST+UE_id],r_im[NB_eNB_INST+UE_id],r_re0_d[UE_id][eNB_id],r_im0_d[UE_id][eNB_id],frame_parms); } } // if(UE_id==NB_UE_INST) // pthread_join(thread, NULL); //} for (UE_id = oai_emulation.info.first_ue_local; UE_id < (oai_emulation.info.first_ue_local + oai_emulation.info.nb_ue_local); UE_id++){ for (eNB_id=oai_emulation.info.first_enb_local;eNB_id<(oai_emulation.info.first_enb_local+oai_emulation.info.nb_enb_local);eNB_id++) { // pthread_join(thread, NULL); //pthread_join(thread[eNB_id][UE_id], NULL); } } // } st2->EResp_FLAG=0; count=0; for (UE_id = oai_emulation.info.first_ue_local; UE_id < (oai_emulation.info.first_ue_local + oai_emulation.info.nb_ue_local); UE_id++) if (mac_xface->frame >= (UE_id * 10)) { // activate UE only after 10*UE_id frames so that different UEs turn on separately send_exec_msg(next_slot,last_slot,mac_xface->frame,mac_xface->frame,slot,0,38820+UE_id); printf("Waiting for Exec Msg Complete \n"); //n = openairIoSyncCreateThread_2(&this->m_io_sync); // n=trig_wait((void*)&this->m_io_sync); } else{ st2->EResp_FLAG=st2->EResp_FLAG+1; count++; } while(count<NB_UE_INST){ n=trig_wait((void*)&this->m_io_sync); count++; } //while(st2->EResp_FLAG<NB_UE_INST) // { // n = select(this->m_io_sync.hfd, &read_ibits, NULL, NULL,NULL); // FD_ISSET(this->m_io_sync.io_sync_entries->fd_read, &read_ibits); // printf(".."); // } } else if(dir_flag==2) { st2->EResp_FLAG=0; count=0; for (UE_id = oai_emulation.info.first_ue_local; UE_id < (oai_emulation.info.first_ue_local + oai_emulation.info.nb_ue_local); UE_id++) if (mac_xface->frame >= (UE_id * 10)) { // activate UE only after 10*UE_id frames so that different UEs turn on separately send_exec_msg(next_slot,last_slot,mac_xface->frame,mac_xface->frame,slot,0,38820+UE_id); // printf("Waiting for Exec Msg Complete \n"); // n = openairIoSyncCreateThread_2(&this->m_io_sync); // n=trig_wait((void*)&this->m_io_sync); } else{ st2->EResp_FLAG=st2->EResp_FLAG+1; count++; } while(count<NB_UE_INST){ n=trig_wait((void*)&this->m_io_sync); count++; } //while(st2->EResp_FLAG<NB_UE_INST) // { // n = select(this->m_io_sync.hfd, &read_ibits, NULL, NULL,NULL); // FD_ISSET(this->m_io_sync.io_sync_entries->fd_read, &read_ibits); // printf(".."); // } // do_UL_sig_channel2(1,0,r_re0,r_im0,r_re,r_im,s_re,s_im,UE2eNB,next_slot,abstraction_flag,frame_parms); // do_UL_sig_channel(r_re0,r_im0,r_re,r_im,s_re,s_im,UE2eNB,next_slot,abstraction_flag,frame_parms); for (eNB_id=oai_emulation.info.first_enb_local;eNB_id<(oai_emulation.info.first_enb_local+oai_emulation.info.nb_enb_local);eNB_id++) { for (UE_id = oai_emulation.info.first_ue_local; UE_id < (oai_emulation.info.first_ue_local + oai_emulation.info.nb_ue_local); UE_id++){ e2u_t[eNB_id][UE_id]->eNB_id=eNB_id; e2u_t[eNB_id][UE_id]->UE_id=UE_id; e2u_t[eNB_id][UE_id]->r_re=r_re[eNB_id]; e2u_t[eNB_id][UE_id]->r_im=r_im[eNB_id]; e2u_t[eNB_id][UE_id]->r_re0=r_re0_u[eNB_id][UE_id]; e2u_t[eNB_id][UE_id]->r_im0=r_im0_u[eNB_id][UE_id]; e2u_t[eNB_id][UE_id]->s_im=s_im[NB_eNB_INST+UE_id]; e2u_t[eNB_id][UE_id]->s_re=s_re[NB_eNB_INST+UE_id]; e2u_t[eNB_id][UE_id]->eNB2UE=eNB2UE[eNB_id][UE_id]; e2u_t[eNB_id][UE_id]->UE2eNB=UE2eNB[UE_id][eNB_id]; e2u_t[eNB_id][UE_id]->enb_data=enb_data[eNB_id]; e2u_t[eNB_id][UE_id]->ue_data=ue_data[UE_id]; e2u_t[eNB_id][UE_id]->next_slot=&next_slot; e2u_t[eNB_id][UE_id]->abstraction_flag=&abstraction_flag; e2u_t[eNB_id][UE_id]->frame_parms=frame_parms; pthread_create (&cthr_u[eNB_id][UE_id], NULL, do_UL_sig_channel_T,(void*)e2u_t[eNB_id][UE_id]); // pthread_create (&thread[eNB_id][UE_id], NULL, do_UL_sig_channel_T,(void*)cthread); // do_UL_sig_channel(eNB_id,UE_id,r_re0,r_im0,r_re[eNB_id],r_im[eNB_id],s_re[NB_eNB_INST+UE_id],s_im[NB_eNB_INST+UE_id],UE2eNB,next_slot,abstraction_flag,frame_parms); // do_UL_sig_channel(eNB_id,UE_id,r_re0_u[eNB_id][UE_id],r_im0_u[eNB_id][UE_id],r_re[eNB_id],r_im[eNB_id],s_re[NB_eNB_INST+UE_id],s_im[NB_eNB_INST+UE_id],UE2eNB,next_slot,abstraction_flag,frame_parms); } } for (eNB_id=oai_emulation.info.first_enb_local;eNB_id<(oai_emulation.info.first_enb_local+oai_emulation.info.nb_enb_local);eNB_id++) { for (UE_id = oai_emulation.info.first_ue_local; UE_id < (oai_emulation.info.first_ue_local + oai_emulation.info.nb_ue_local); UE_id++){ // pthread_join(thread[eNB_id][UE_id], NULL); pthread_join(cthr_u[eNB_id][UE_id], NULL); } } for (eNB_id=oai_emulation.info.first_enb_local;eNB_id<(oai_emulation.info.first_enb_local+oai_emulation.info.nb_enb_local);eNB_id++) { clean_param(r_re[eNB_id],r_im[eNB_id],frame_parms); for (UE_id = oai_emulation.info.first_ue_local; UE_id < (oai_emulation.info.first_ue_local + oai_emulation.info.nb_ue_local); UE_id++){ channel_add(r_re[eNB_id],r_im[eNB_id],r_re0_u[eNB_id][UE_id],r_im0_u[eNB_id][UE_id],frame_parms); } } // } st2->EResp_FLAG=0; count=0; for (eNB_id=oai_emulation.info.first_enb_local;eNB_id<(oai_emulation.info.first_enb_local+oai_emulation.info.nb_enb_local);eNB_id++) { send_exec_msg(next_slot,last_slot,mac_xface->frame,mac_xface->frame,slot,0,38810+eNB_id); // n = openairIoSyncCreateThread_2(&this->m_io_sync); // n=trig_wait((void*)&this->m_io_sync); // printf("Waiting for Exec Msg Complete \n"); } // for loop while(count<NB_eNB_INST){ n=trig_wait((void*)&this->m_io_sync); count++; } // while(st2->EResp_FLAG<NB_eNB_INST) // { // n = select(this->m_io_sync.hfd, &read_ibits, NULL, NULL,NULL); // FD_ISSET(this->m_io_sync.io_sync_entries->fd_read, &read_ibits); // // printf(".."); // } } if ((last_slot == 1) && (mac_xface->frame == 0) && (abstraction_flag == 0) && (oai_emulation.info.n_frames == 1)) { // write_output ("dlchan0.m", "dlch0", // &(PHY_vars_UE_g[0]->lte_ue_common_vars.dl_ch_estimates[0][0][0]), // (6 * (PHY_vars_UE_g[0]->lte_frame_parms.ofdm_symbol_size)), 1, 1); // write_output ("dlchan1.m", "dlch1", // &(PHY_vars_UE_g[0]->lte_ue_common_vars.dl_ch_estimates[1][0][0]), // (6 * (PHY_vars_UE_g[0]->lte_frame_parms.ofdm_symbol_size)), 1, 1); // write_output ("dlchan2.m", "dlch2", // &(PHY_vars_UE_g[0]->lte_ue_common_vars.dl_ch_estimates[2][0][0]), // (6 * (PHY_vars_UE_g[0]->lte_frame_parms.ofdm_symbol_size)), 1, 1); // write_output ("pbch_rxF_comp0.m", "pbch_comp0", // PHY_vars_UE_g[0]->lte_ue_pbch_vars[0]->rxdataF_comp[0], 6 * 12 * 4, 1, 1); // write_output ("pbch_rxF_llr.m", "pbch_llr", // PHY_vars_UE_g[0]->lte_ue_pbch_vars[0]->llr, (frame_parms->Ncp == 0) ? 1920 : 1728, 1, 4); } /* if ((last_slot==1) && (mac_xface->frame==1)) { write_output("dlsch_rxF_comp0.m","dlsch0_rxF_comp0",PHY_vars_UE->lte_ue_dlsch_vars[eNB_id]->rxdataF_comp[0],300*(-(PHY_vars_UE->lte_frame_parms.Ncp*2)+14),1,1); write_output("pdcch_rxF_comp0.m","pdcch0_rxF_comp0",PHY_vars_UE->lte_ue_pdcch_vars[eNB_id]->rxdataF_comp[0],4*300,1,1); } */ if (next_slot %2 == 0){ clock_gettime (CLOCK_REALTIME, &time_spec); time_last = time_now; time_now = (unsigned long) time_spec.tv_nsec; td = (int) (time_now - time_last); if (td>0) { td_avg = (int)(((K*(long)td) + (((1<<3)-K)*((long)td_avg)))>>3); // in us LOG_I(EMU,"sleep frame %d, average time difference %ldns, CURRENT TIME DIFF %dus, avgerage difference from the target %dus\n", mac_xface->frame, td_avg, td/1000,(td_avg-TARGET_SF_TIME_NS)/1000); } if (td_avg<(TARGET_SF_TIME_NS - SF_DEVIATION_OFFSET_NS)){ sleep_time_us += SLEEP_STEP_US; } else if (td_avg > (TARGET_SF_TIME_NS + SF_DEVIATION_OFFSET_NS)) { sleep_time_us-= SLEEP_STEP_US; } }// end if next_slot%2 } //end of slot
int main(int argc, char **argv) { #ifdef RTAI RT_TASK *task; RTIME period; #endif int i,j,aa; void *status; /* uint32_t rf_mode_max[4] = {55759,55759,55759,55759}; uint32_t rf_mode_med[4] = {39375,39375,39375,39375}; uint32_t rf_mode_byp[4] = {22991,22991,22991,22991}; */ uint32_t my_rf_mode = RXEN + TXEN + TXLPFNORM + TXLPFEN + TXLPF25 + RXLPFNORM + RXLPFEN + RXLPF25 + LNA1ON +LNAMax + RFBBNORM + DMAMODE_RX + DMAMODE_TX; uint32_t rf_mode_base = TXLPFNORM + TXLPFEN + TXLPF25 + RXLPFNORM + RXLPFEN + RXLPF25 + LNA1ON +LNAMax + RFBBNORM; uint32_t rf_mode[4] = {my_rf_mode,0,0,0}; uint32_t rf_local[4] = {8255000,8255000,8255000,8255000}; // UE zepto //{8254617, 8254617, 8254617, 8254617}; //eNB khalifa //{8255067,8254810,8257340,8257340}; // eNB PETRONAS uint32_t rf_vcocal[4] = {910,910,910,910}; uint32_t rf_vcocal_850[4] = {2015, 2015, 2015, 2015}; uint32_t rf_rxdc[4] = {32896,32896,32896,32896}; uint32_t rxgain[4] = {20,20,20,20}; uint32_t txgain[4] = {20,20,20,20}; uint16_t Nid_cell = 0; uint8_t cooperation_flag=0, transmission_mode=1, abstraction_flag=0; uint8_t beta_ACK=0,beta_RI=0,beta_CQI=2; int c; char do_forms=0; unsigned int fd; unsigned int tcxo = 114; int amp; uint8_t prach_fmt; int N_ZC; char rxg_fname[100]; char txg_fname[100]; char rflo_fname[100]; char rfdc_fname[100]; FILE *rxg_fd=NULL; FILE *txg_fd=NULL; FILE *rflo_fd=NULL; FILE *rfdc_fd=NULL; unsigned int rxg_max[4]={133,133,133,133}, rxg_med[4]={127,127,127,127}, rxg_byp[4]={120,120,120,120}; int tx_max_power=0; char line[1000]; int l; int ret, ant; int ant_offset=0; int error_code; char *itti_dump_file = NULL; const struct option long_options[] = { {"calib-ue-rx", required_argument, NULL, 256}, {"calib-ue-rx-med", required_argument, NULL, 257}, {"calib-ue-rx-byp", required_argument, NULL, 258}, {"debug-ue-prach", no_argument, NULL, 259}, {"no-L2-connect", no_argument, NULL, 260}, {NULL, 0, NULL, 0}}; //mode = normal_txrx; while ((c = getopt_long (argc, argv, "C:K:O:ST:UdF:V",long_options,NULL)) != -1) { switch (c) { case 'V': ouput_vcd = 1; break; case 'd': do_forms=1; break; case 'U': UE_flag = 1; break; case 'C': carrier_freq[0] = atoi(optarg); carrier_freq[1] = atoi(optarg); carrier_freq[2] = atoi(optarg); carrier_freq[3] = atoi(optarg); break; case 'S': fs4_test=1; break; case 'T': tcxo=atoi(optarg); break; case 'K': #if defined(ENABLE_ITTI) itti_dump_file = strdup(optarg); #else printf("-K option is disabled when ENABLE_ITTI is not defined\n"); #endif break; case 'O': #if defined(ENABLE_USE_MME) EPC_MODE_ENABLED = 1; if (optarg == NULL) /* No IP address provided: use localhost */ { memcpy(&EPC_MODE_MME_ADDRESS[0], "127.0.0.1", 10); } else { uint8_t ip_length = strlen(optarg) + 1; memcpy(&EPC_MODE_MME_ADDRESS[0], optarg, ip_length > 16 ? 16 : ip_length); } #else printf("You enabled mme mode without s1ap compiled...\n"); #endif break; case 'F': sprintf(rxg_fname,"%srxg.lime",optarg); rxg_fd = fopen(rxg_fname,"r"); if (rxg_fd) { printf("Loading RX Gain parameters from %s\n",rxg_fname); l=0; while (fgets(line, sizeof(line), rxg_fd)) { if ((strlen(line)==0) || (*line == '#')) continue; //ignore empty or comment lines else { if (l==0) sscanf(line,"%d %d %d %d",&rxg_max[0],&rxg_max[1],&rxg_max[2],&rxg_max[3]); if (l==1) sscanf(line,"%d %d %d %d",&rxg_med[0],&rxg_med[1],&rxg_med[2],&rxg_med[3]); if (l==2) sscanf(line,"%d %d %d %d",&rxg_byp[0],&rxg_byp[1],&rxg_byp[2],&rxg_byp[3]); l++; } } } else printf("%s not found, running with defaults\n",rxg_fname); sprintf(txg_fname,"%stxg.lime",optarg); txg_fd = fopen(txg_fname,"r"); if (txg_fd) { printf("Loading TX Gain parameters from %s\n",txg_fname); l=0; while (fgets(line, sizeof(line), txg_fd)) { if ((strlen(line)==0) || (*line == '#')) { continue; //ignore empty or comment lines } else { if (l==0) sscanf(line,"%d %d %d %d",&txgain[0],&txgain[1],&txgain[2],&txgain[3]); if (l==1) sscanf(line,"%d",&tx_max_power); l++; } } } else printf("%s not found, running with defaults\n",txg_fname); sprintf(rflo_fname,"%srflo.lime",optarg); rflo_fd = fopen(rflo_fname,"r"); if (rflo_fd) { printf("Loading RF LO parameters from %s\n",rflo_fname); fscanf(rflo_fd,"%d %d %d %d",&rf_local[0],&rf_local[1],&rf_local[2],&rf_local[3]); } else printf("%s not found, running with defaults\n",rflo_fname); sprintf(rfdc_fname,"%srfdc.lime",optarg); rfdc_fd = fopen(rfdc_fname,"r"); if (rfdc_fd) { printf("Loading RF DC parameters from %s\n",rfdc_fname); fscanf(rfdc_fd,"%d %d %d %d",&rf_rxdc[0],&rf_rxdc[1],&rf_rxdc[2],&rf_rxdc[3]); } else printf("%s not found, running with defaults\n",rfdc_fname); break; /* case 256: mode = rx_calib_ue; rx_input_level_dBm = atoi(optarg); printf("Running with UE calibration on (LNA max), input level %d dBm\n",rx_input_level_dBm); break; case 257: mode = rx_calib_ue_med; rx_input_level_dBm = atoi(optarg); printf("Running with UE calibration on (LNA med), input level %d dBm\n",rx_input_level_dBm); break; case 258: mode = rx_calib_ue_byp; rx_input_level_dBm = atoi(optarg); printf("Running with UE calibration on (LNA byp), input level %d dBm\n",rx_input_level_dBm); break; case 259: mode = debug_prach; break; case 260: mode = no_L2_connect; break; */ default: break; } } if (UE_flag==1) printf("configuring for UE\n"); else printf("configuring for eNB\n"); //randominit (0); //set_taus_seed (0); // initialize the log (see log.h for details) logInit(); #if defined(ENABLE_ITTI) itti_init(TASK_MAX, THREAD_MAX, MESSAGES_ID_MAX, tasks_info, messages_info, messages_definition_xml, itti_dump_file); # if defined(ENABLE_USE_MME) if (itti_create_task(TASK_SCTP, sctp_eNB_task, NULL) < 0) { LOG_E(EMU, "Create task failed"); LOG_D(EMU, "Initializing SCTP task interface: FAILED\n"); return -1; } if (itti_create_task(TASK_S1AP, s1ap_eNB_task, NULL) < 0) { LOG_E(EMU, "Create task failed"); LOG_D(EMU, "Initializing S1AP task interface: FAILED\n"); return -1; } # endif if (itti_create_task(TASK_L2L1, l2l1_task, NULL) < 0) { LOG_E(EMU, "Create task failed"); LOG_D(EMU, "Initializing L2L1 task interface: FAILED\n"); return -1; } // Handle signals until all tasks are terminated // itti_wait_tasks_end(); #endif if (ouput_vcd) { if (UE_flag==1) vcd_signal_dumper_init("/tmp/openair_dump_UE.vcd"); else vcd_signal_dumper_init("/tmp/openair_dump_eNB.vcd"); } #ifdef NAS_NETLINK netlink_init(); #endif // to make a graceful exit when ctrl-c is pressed signal(SIGSEGV, signal_handler); signal(SIGINT, signal_handler); #ifndef RTAI check_clock(); #endif g_log->log_component[HW].level = LOG_DEBUG; g_log->log_component[HW].flag = LOG_HIGH; #ifdef OPENAIR2 g_log->log_component[PHY].level = LOG_INFO; #else g_log->log_component[PHY].level = LOG_INFO; #endif g_log->log_component[PHY].flag = LOG_HIGH; g_log->log_component[MAC].level = LOG_INFO; g_log->log_component[MAC].flag = LOG_HIGH; g_log->log_component[RLC].level = LOG_INFO; g_log->log_component[RLC].flag = LOG_HIGH; g_log->log_component[PDCP].level = LOG_INFO; g_log->log_component[PDCP].flag = LOG_HIGH; g_log->log_component[OTG].level = LOG_INFO; g_log->log_component[OTG].flag = LOG_HIGH; g_log->log_component[RRC].level = LOG_INFO; g_log->log_component[RRC].flag = LOG_HIGH; // Initialize card ret = openair0_open(); if ( ret != 0 ) { if (ret == -1) printf("Error opening /dev/openair0"); if (ret == -2) printf("Error mapping bigshm"); if (ret == -3) printf("Error mapping RX or TX buffer"); return(ret); } printf ("Detected %d number of cards, %d number of antennas.\n", openair0_num_detected_cards, openair0_num_antennas[card]); p_exmimo_config = openair0_exmimo_pci[card].exmimo_config_ptr; p_exmimo_id = openair0_exmimo_pci[card].exmimo_id_ptr; printf("Card %d: ExpressMIMO %d, HW Rev %d, SW Rev 0x%d\n", card, p_exmimo_id->board_exmimoversion, p_exmimo_id->board_hwrev, p_exmimo_id->board_swrev); if (p_exmimo_id->board_swrev>=BOARD_SWREV_CNTL2) p_exmimo_config->framing.eNB_flag = 0; else p_exmimo_config->framing.eNB_flag = !UE_flag; p_exmimo_config->framing.tdd_config = DUPLEXMODE_FDD + TXRXSWITCH_LSB; for (ant=0; ant<4; ant++) p_exmimo_config->framing.resampling_factor[ant] = RESAMPLING_FACTOR; /* for (ant=0;ant<max(frame_parms->nb_antennas_tx,frame_parms->nb_antennas_rx);ant++) p_exmimo_config->rf.rf_mode[ant] = rf_mode_base; for (ant=0;ant<frame_parms->nb_antennas_tx;ant++) p_exmimo_config->rf.rf_mode[ant] += (TXEN + DMAMODE_TX); for (ant=0;ant<frame_parms->nb_antennas_rx;ant++) p_exmimo_config->rf.rf_mode[ant] += (RXEN + DMAMODE_RX); for (ant=max(frame_parms->nb_antennas_tx,frame_parms->nb_antennas_rx);ant<4;ant++) { p_exmimo_config->rf.rf_mode[ant] = 0; carrier_freq[ant] = 0; //this turns off all other LIMEs } */ ant_offset = 0; for (ant=0; ant<4; ant++) { if (ant==ant_offset) { //if (1) { p_exmimo_config->rf.rf_mode[ant] = rf_mode_base; //p_exmimo_config->rf.rf_mode[ant] += (TXEN + DMAMODE_TX); p_exmimo_config->rf.rf_mode[ant] += (RXEN + DMAMODE_RX); } else { p_exmimo_config->rf.rf_mode[ant] = 0; carrier_freq[ant] = 0; //this turns off all other LIMEs } } for (ant = 0; ant<4; ant++) { p_exmimo_config->rf.do_autocal[ant] = 1; p_exmimo_config->rf.rf_freq_rx[ant] = carrier_freq[ant]; p_exmimo_config->rf.rf_freq_tx[ant] = carrier_freq[ant]; p_exmimo_config->rf.rx_gain[ant][0] = rxgain[ant]; p_exmimo_config->rf.tx_gain[ant][0] = txgain[ant]; p_exmimo_config->rf.rf_local[ant] = rf_local[ant]; p_exmimo_config->rf.rf_rxdc[ant] = rf_rxdc[ant]; if ((carrier_freq[ant] >= 850000000) && (carrier_freq[ant] <= 865000000)) { p_exmimo_config->rf.rf_vcocal[ant] = rf_vcocal_850[ant]; p_exmimo_config->rf.rffe_band_mode[ant] = DD_TDD; } else if ((carrier_freq[ant] >= 1900000000) && (carrier_freq[ant] <= 2000000000)) { p_exmimo_config->rf.rf_vcocal[ant] = rf_vcocal[ant]; p_exmimo_config->rf.rffe_band_mode[ant] = B19G_TDD; } else { p_exmimo_config->rf.rf_vcocal[ant] = rf_vcocal[ant]; p_exmimo_config->rf.rffe_band_mode[ant] = 0; } p_exmimo_config->rf.rffe_gain_txlow[ant] = 31; p_exmimo_config->rf.rffe_gain_txhigh[ant] = 31; p_exmimo_config->rf.rffe_gain_rxfinal[ant] = 52; p_exmimo_config->rf.rffe_gain_rxlow[ant] = 31; } number_of_cards = openair0_num_detected_cards; /* if (p_exmimo_id->board_exmimoversion==1) //ExpressMIMO1 openair_daq_vars.timing_advance = 138; else //ExpressMIMO2 openair_daq_vars.timing_advance = 0; */ openair0_dump_config(card); printf("EXMIMO_CONFIG: rf_mode 0x %x %x %x %x, [0]: TXRXEn %d, TXLPFEn %d, TXLPF %d, RXLPFEn %d, RXLPF %d, RFBB %d, LNA %d, LNAGain %d, RXLPFMode %d, SWITCH %d, rf_rxdc %d, rf_local %d, rf_vcocal %d\n", p_exmimo_config->rf.rf_mode[0], p_exmimo_config->rf.rf_mode[1], p_exmimo_config->rf.rf_mode[2], p_exmimo_config->rf.rf_mode[3], (p_exmimo_config->rf.rf_mode[0]&3), // RXen+TXen (p_exmimo_config->rf.rf_mode[0]&4)>>2, //TXLPFen (p_exmimo_config->rf.rf_mode[0]&TXLPFMASK)>>3, //TXLPF (p_exmimo_config->rf.rf_mode[0]&128)>>7, //RXLPFen (p_exmimo_config->rf.rf_mode[0]&RXLPFMASK)>>8, //TXLPF (p_exmimo_config->rf.rf_mode[0]&RFBBMASK)>>16, // RFBB mode (p_exmimo_config->rf.rf_mode[0]&LNAMASK)>>12, // RFBB mode (p_exmimo_config->rf.rf_mode[0]&LNAGAINMASK)>>14, // RFBB mode (p_exmimo_config->rf.rf_mode[0]&RXLPFMODEMASK)>>19, // RXLPF mode (p_exmimo_config->framing.tdd_config&TXRXSWITCH_MASK)>>1, // Switch mode p_exmimo_config->rf.rf_rxdc[0], p_exmimo_config->rf.rf_local[0], p_exmimo_config->rf.rf_vcocal[0]); for (ant=0;ant<4;ant++) p_exmimo_config->rf.do_autocal[ant] = 0; #ifdef EMOS error_code = rtf_create(CHANSOUNDER_FIFO_MINOR,CHANSOUNDER_FIFO_SIZE); if (error_code==0) printf("[OPENAIR][SCHED][INIT] Created EMOS FIFO %d\n",CHANSOUNDER_FIFO_MINOR); else if (error_code==ENODEV) printf("[OPENAIR][SCHED][INIT] Problem: EMOS FIFO %d is greater than or equal to RTF_NO\n",CHANSOUNDER_FIFO_MINOR); else if (error_code==ENOMEM) printf("[OPENAIR][SCHED][INIT] Problem: cannot allocate memory for EMOS FIFO %d\n",CHANSOUNDER_FIFO_MINOR); else printf("[OPENAIR][SCHED][INIT] Problem creating EMOS FIFO %d, error_code %d\n",CHANSOUNDER_FIFO_MINOR,error_code); #endif mlockall(MCL_CURRENT | MCL_FUTURE); #ifdef RTAI // make main thread LXRT soft realtime task = rt_task_init_schmod(nam2num("MYTASK"), 9, 0, 0, SCHED_FIFO, 0xF); // start realtime timer and scheduler #ifdef TIMER_ONESHOT_MODE rt_set_oneshot_mode(); start_rt_timer(0); printf("started RTAI timer inoneshot mode\n"); #else rt_set_periodic_mode(); period = start_rt_timer(nano2count(500000)); printf("started RTAI timer with period %llu ns\n",count2nano(period)); #endif printf("Init mutex\n"); //mutex = rt_get_adr(nam2num("MUTEX")); mutex = rt_sem_init(nam2num("MUTEX"), 1); if (mutex==0) { printf("Error init mutex\n"); exit(-1); } else printf("mutex=%p\n",mutex); #endif DAQ_MBOX = (volatile unsigned int *) openair0_exmimo_pci[card].rxcnt_ptr[0]; // this starts the DMA transfers if (UE_flag!=1) openair0_start_rt_acquisition(card); #ifdef XFORMS if (do_forms==1) { fl_initialize (&argc, argv, NULL, 0, 0); form_stats = create_form_stats_form(); if (UE_flag==1) { form_ue[UE_id] = create_lte_phy_scope_ue(); sprintf (title, "LTE DL SCOPE UE"); fl_show_form (form_ue[UE_id]->lte_phy_scope_ue, FL_PLACE_HOTSPOT, FL_FULLBORDER, title); } else { for(UE_id=0;UE_id<scope_enb_num_ue;UE_id++) { form_enb[UE_id] = create_lte_phy_scope_enb(); sprintf (title, "UE%d LTE UL SCOPE eNB",UE_id+1); fl_show_form (form_enb[UE_id]->lte_phy_scope_enb, FL_PLACE_HOTSPOT, FL_FULLBORDER, title); } } fl_show_form (form_stats->stats_form, FL_PLACE_HOTSPOT, FL_FULLBORDER, "stats"); if (UE_flag==0) { for (UE_id=0;UE_id<scope_enb_num_ue;UE_id++) { if (otg_enabled) { fl_set_button(form_enb[UE_id]->button_0,1); fl_set_object_label(form_enb[UE_id]->button_0,"DL Traffic ON"); } else { fl_set_button(form_enb[UE_id]->button_0,0); fl_set_object_label(form_enb[UE_id]->button_0,"DL Traffic OFF"); } } } else { if (openair_daq_vars.use_ia_receiver) { fl_set_button(form_ue[UE_id]->button_0,1); fl_set_object_label(form_ue[UE_id]->button_0, "IA Receiver ON"); } else { fl_set_button(form_ue[UE_id]->button_0,0); fl_set_object_label(form_ue[UE_id]->button_0, "IA Receiver OFF"); } } ret = pthread_create(&thread2, NULL, scope_thread, NULL); printf("Scope thread created, ret=%d\n",ret); } #endif #ifdef EMOS ret = pthread_create(&thread3, NULL, emos_thread, NULL); printf("EMOS thread created, ret=%d\n",ret); #endif rt_sleep_ns(10*FRAME_PERIOD); #ifndef RTAI pthread_attr_init (&attr_dlsch_threads); pthread_attr_setstacksize(&attr_dlsch_threads,OPENAIR_THREAD_STACK_SIZE); //attr_dlsch_threads.priority = 1; sched_param_dlsch.sched_priority = sched_get_priority_max(SCHED_FIFO); //OPENAIR_THREAD_PRIORITY; pthread_attr_setschedparam (&attr_dlsch_threads, &sched_param_dlsch); pthread_attr_setschedpolicy (&attr_dlsch_threads, SCHED_FIFO); #endif // start the main thread if (UE_flag == 1) { /* #ifdef RTAI thread1 = rt_thread_create(UE_thread, NULL, 100000000); #else error_code = pthread_create(&thread1, &attr_dlsch_threads, UE_thread, NULL); if (error_code!= 0) { LOG_D(HW,"[lte-softmodem.c] Could not allocate UE_thread, error %d\n",error_code); return(error_code); } else { LOG_D(HW,"[lte-softmodem.c] Allocate UE_thread successful\n"); } #endif #ifdef DLSCH_THREAD init_rx_pdsch_thread(); rt_sleep_ns(FRAME_PERIOD/10); init_dlsch_threads(); #endif printf("UE threads created\n"); */ } else { #ifdef RTAI thread0 = rt_thread_create(eNB_thread, NULL, 100000000); #else error_code = pthread_create(&thread0, &attr_dlsch_threads, eNB_thread, NULL); if (error_code!= 0) { LOG_D(HW,"[lte-softmodem.c] Could not allocate eNB_thread, error %d\n",error_code); return(error_code); } else { LOG_D(HW,"[lte-softmodem.c] Allocate eNB_thread successful\n"); } #endif #ifdef ULSCH_THREAD init_ulsch_threads(); #endif printf("eNB threads created\n"); } // wait for end of program printf("TYPE <CTRL-C> TO TERMINATE\n"); //getchar(); while (oai_exit==0) rt_sleep_ns(FRAME_PERIOD); // stop threads #ifdef XFORMS printf("waiting for XFORMS thread\n"); if (do_forms==1) { pthread_join(thread2,&status); fl_hide_form(form_stats->stats_form); fl_free_form(form_stats->stats_form); if (UE_flag==1) { fl_hide_form(form_ue[UE_id]->lte_phy_scope_ue); fl_free_form(form_ue[UE_id]->lte_phy_scope_ue); } else { for(UE_id=0;UE_id<scope_enb_num_ue;UE_id++) { fl_hide_form(form_enb[UE_id]->lte_phy_scope_enb); fl_free_form(form_enb[UE_id]->lte_phy_scope_enb); } } } #endif printf("stopping MODEM threads\n"); // cleanup if (UE_flag == 1) { /* #ifdef RTAI rt_thread_join(thread1); #else pthread_join(thread1,&status); #endif #ifdef DLSCH_THREAD cleanup_dlsch_threads(); cleanup_rx_pdsch_thread(); #endif */ } else { #ifdef RTAI rt_thread_join(thread0); #else pthread_join(thread0,&status); #endif #ifdef ULSCH_THREAD cleanup_ulsch_threads(); #endif } #ifdef OPENAIR2 //cleanup_pdcp_thread(); #endif #ifdef RTAI stop_rt_timer(); #endif printf("stopping card\n"); openair0_stop(card); printf("closing openair0_lib\n"); openair0_close(); #ifdef EMOS printf("waiting for EMOS thread\n"); pthread_cancel(thread3); pthread_join(thread3,&status); #endif #ifdef EMOS error_code = rtf_destroy(CHANSOUNDER_FIFO_MINOR); printf("[OPENAIR][SCHED][CLEANUP] EMOS FIFO closed, error_code %d\n", error_code); #endif if (ouput_vcd) vcd_signal_dumper_close(); logClean(); return 0; }