/** * User registration handler. * * @param cfg Configuration options. * @param ec Error Code. */ void mih_user::user_reg_handler(const odtone::mih::config& cfg, const boost::system::error_code& ec) { log_(0, "MIH-User register result: ", ec.message()); odtone::mih::message msg; odtone::mih::octet_string destination = cfg.get<odtone::mih::octet_string>(odtone::sap::kConf_MIH_SAP_dest); _mihfid.assign(destination.c_str()); // // Let's fire a capability discover request to get things moving // msg << odtone::mih::request(odtone::mih::request::capability_discover, _mihfid); _mihf.async_send(msg, boost::bind(&mih_user::capability_discover_confirm, this, _1, _2)); log_(0, "MIH-User has sent a Capability_Discover.request towards its local MIHF"); }
/** * * Create and send a MIH_Link_Get_Parameters.request message. * * * * @param sap The SAP helper. * * @param dst The destination MIH ID. * */ void mih_user::send_link_get_parameters_request() { odtone::mih::message p; odtone::mih::link_tuple_id li,li1; odtone::mih::link_id_list lil; odtone::mih::mac_addr mac,mac1; log_(0, "sending link_get_parameters_request"); mac.address("00:26:b6:4e:af:6c"); mac1.address("00:13:77:bf:f0:ef"); li.type = odtone::mih::link_type_802_11; li.addr = mac; lil.push_back(li); odtone::mih::link_status_req lsr; //odtone::mih::link_param_802_11 lp = odtone::mih::link_param_802_11_rssi; lsr._states_req.set(odtone::mih::link_states_req_op_mode); //lsr._param_type_list.push_back(lp); // lsr._desc_req.set(odtone::mih::link_desc_req_classes_of_service_supported); odtone::mih::link_param_gen lpgs = odtone::mih::link_param_gen_signal_strength; lsr._param_type_list.push_back(lpgs); odtone::mih::link_param_gen lpgd = odtone::mih::link_param_gen_data_rate; lsr._param_type_list.push_back(lpgd); odtone::mih::link_param_gen lpgp = odtone::mih::link_param_gen_packet_error_rate; lsr._param_type_list.push_back(lpgp); p << odtone::mih::request(odtone::mih::request::link_get_parameters, _mihfid) & odtone::mih::tlv_link_id_list(lil) & odtone::mih::tlv_get_status_req_set(lsr); _mihf.async_send(p, boost::bind(&mih_user::link_get_parameters_request_handler, this, _1, _2)); }
/** * Capability Discover handler. * * @param msg Received message. * @param ec Error Code. */ void mih_user::capability_discover_confirm(odtone::mih::message& msg, const boost::system::error_code& ec) { if (ec) { log_(0, __FUNCTION__, " error: ", ec.message()); return; } odtone::mih::status st; boost::optional<odtone::mih::net_type_addr_list> ntal; boost::optional<odtone::mih::mih_evt_list> evt; msg >> odtone::mih::confirm() & odtone::mih::tlv_status(st) & odtone::mih::tlv_net_type_addr_list(ntal) & odtone::mih::tlv_event_list(evt); log_(0, "MIH-User has received a Capability_Discover.response with status ", st.get(), " and the following capabilities:"); /*odtone::uint i = 0; odtone::uint size = ntal.size(); for (;i < size; i++) { odtone::mih::mac_addr mac = boost::get<odtone::mih::mac_addr>(ntal[i].addr); odonte::mih::network_type type = ntal[i].nettype; switch type: case odtone::mih::link_type_802_11: log_(0, "detected wifi w/ addr = ", mac); break; case odtone::mih::link_type_ethernet: log_(0, "detected ethernet w/ addr = ", mac); break; }*/ //log_(0, "prima for"); for (odtone::mih::net_type_addr_list::iterator i = ntal->begin(); i != ntal->end(); ++i) { /*log_(0, "inizio"); log_(0, *i); log_(0, "fine");*/ //odtone::mih::link_tuple_id li; if (i->nettype.link.which() == 1) { odtone::mih::mac_addr mac = boost::get<odtone::mih::mac_addr>(i->addr); odtone::mih::link_type type = boost::get<odtone::mih::link_type>(i->nettype.link); this->links.add_interface(mac,type); } } this->links.print_interfaces(); // // event subscription // // For every interface the MIHF sent in the // Capability_Discover.response send an Event_Subscribe.request // for all availabe events // if (ntal && evt) { for (odtone::mih::net_type_addr_list::iterator i = ntal->begin(); i != ntal->end(); ++i) { odtone::mih::message req; odtone::mih::link_tuple_id li; if (i->nettype.link.which() == 1) { li.addr = i->addr; li.type = boost::get<odtone::mih::link_type>(i->nettype.link); req << odtone::mih::request(odtone::mih::request::event_subscribe, _mihfid) & odtone::mih::tlv_link_identifier(li) & odtone::mih::tlv_event_list(evt); req.destination(msg.source()); _mihf.async_send(req, boost::bind(&mih_user::event_subscribe_response, this, _1, _2)); log_(0, "MIH-User has sent Event_Subscribe.request to ", req.destination().to_string()); } } } }
/** * Capability Discover handler. * * @param msg Received message. * @param ec Error Code. */ void mih_user::capability_discover_confirm(odtone::mih::message& msg, const boost::system::error_code& ec) { if (ec) { log_(0, __FUNCTION__, " error: ", ec.message()); return; } odtone::mih::status st; boost::optional<odtone::mih::net_type_addr_list> ntal; boost::optional<odtone::mih::mih_evt_list> evt; msg >> odtone::mih::confirm() & odtone::mih::tlv_status(st) & odtone::mih::tlv_net_type_addr_list(ntal) & odtone::mih::tlv_event_list(evt); log_(0, "MIH-User has received a Capability_Discover.response with status ", st.get(), " and the following capabilities:"); if (ntal) { for (odtone::mih::net_type_addr_list::iterator i = ntal->begin(); i != ntal->end(); ++i) log_(0, *i); } else { log_(0, "none"); } // // event subscription // // For every interface the MIHF sent in the // Capability_Discover.response send an Event_Subscribe.request // for all availabe events // if (ntal && evt) { for (odtone::mih::net_type_addr_list::iterator i = ntal->begin(); i != ntal->end(); ++i) { odtone::mih::message req; odtone::mih::link_tuple_id li; if (i->nettype.link.which() == 1) { li.addr = i->addr; li.type = boost::get<odtone::mih::link_type>(i->nettype.link); //yan-start-23/02/2012 //_mihlid[_num_links] = li; //++_num_links; odtone::mih::octet_string ifname = mih_get_ifname(li); if (ifname != "") { _mihlnks.push_back(link_info(li, ifname)); } //yan-end req << odtone::mih::request(odtone::mih::request::event_subscribe, _mihfid) & odtone::mih::tlv_link_identifier(li) & odtone::mih::tlv_event_list(evt); req.destination(msg.source()); _mihf.async_send(req, boost::bind(&mih_user::event_subscribe_response, this, _1, _2)); log_(0, "MIH-User has sent Event_Subscribe.request to ", req.destination().to_string()); } } } }