/** * Event subscribe handler. * * @param msg Received message. * @param ec Error Code. */ void mih_user::event_subscribe_response(odtone::mih::message& msg, const boost::system::error_code& ec) { log_(0, __FUNCTION__, "(", msg.tid(), ")"); if (ec) { log_(0, __FUNCTION__, " error: ", ec.message()); return; } odtone::mih::status st; msg >> odtone::mih::response() & odtone::mih::tlv_status(st); log_(0, "status: ", st.get()); }
/** * Default MIH event handler. * * @param msg Received message. * @param ec Error code. */ void mih_user::event_handler(odtone::mih::message& msg, const boost::system::error_code& ec) { if (ec) { log_(0, __FUNCTION__, " error : ", ec.message()); send_link_get_parameters_request(); return; } odtone::mih::link_tuple_id li; msg >> odtone::mih::indication() & odtone::mih::tlv_link_identifier(li); odtone::mih::mac_addr mac = boost::get<odtone::mih::mac_addr>(li.addr); odtone::mih::link_type type = boost::get<odtone::mih::link_type>(li.type); switch (msg.mid()) { case odtone::mih::indication::link_up: log_(0, "MIH-User has received a local event \"link_up\""); this->links.add_interface(mac,type); break; case odtone::mih::indication::link_down: log_(0, "MIH-User has received a local event \"link_down\""); this->links.remove_interface(mac); break; case odtone::mih::indication::link_detected: log_(0, "MIH-User has received a local event \"link_detected\""); break; case odtone::mih::indication::link_going_down: log_(0, "MIH-User has received a local event \"link_going_down\""); break; case odtone::mih::indication::link_handover_imminent: log_(0, "MIH-User has received a local event \"link_handover_imminent\""); break; case odtone::mih::indication::link_handover_complete: log_(0, "MIH-User has received a local event \"link_handover_complete\""); break; default: log_(0, "MIH-User has received a local event \"unknown\""); break; } this->links.print_interfaces(); }
/** * Default MIH event handler. * * @param msg Received message. * @param ec Error code. */ void link_sap::default_handler(odtone::mih::message& msg, const boost::system::error_code& ec) { if (ec) return; odtone::mih::status st; switch (msg.mid()) { case odtone::mih::request::capability_discover: { odtone::mih::message m; // fill the status st = odtone::mih::status_success; m << odtone::mih::confirm(odtone::mih::confirm::capability_discover) & odtone::mih::tlv_status(st) & odtone::mih::tlv_link_evt_list(capabilities_event_list) & odtone::mih::tlv_link_cmd_list(capabilities_command_list); m.tid(msg.tid()); _mihf.async_send(m); } break; case odtone::mih::request::event_subscribe: { odtone::mih::link_evt_list events; msg >> odtone::mih::request() & odtone::mih::tlv_link_evt_list(events); odtone::mih::message m; // fill the status st = odtone::mih::status_success; m << odtone::mih::confirm(odtone::mih::confirm::event_subscribe) & odtone::mih::tlv_status(st) & odtone::mih::tlv_link_evt_list(events); m.tid(msg.tid()); _mihf.async_send(m); break; } case odtone::mih::request::event_unsubscribe: { odtone::mih::link_evt_list events; msg >> odtone::mih::request() & odtone::mih::tlv_link_evt_list(events); odtone::mih::message m; // fill the status st = odtone::mih::status_success; m << odtone::mih::confirm(odtone::mih::confirm::event_unsubscribe) & odtone::mih::tlv_status(st) & odtone::mih::tlv_link_evt_list(events); m.tid(msg.tid()); _mihf.async_send(m); break; } case odtone::mih::request::link_get_parameters: { odtone::mih::link_param_list lpl; odtone::mih::link_states_rsp_list lsrl; odtone::mih::link_desc_rsp_list ldrl; odtone::mih::message m; // fill the status st = odtone::mih::status_success; m << odtone::mih::confirm(odtone::mih::confirm::link_get_parameters) & odtone::mih::tlv_status(st) & odtone::mih::tlv_link_parameters_status_list(lpl) & odtone::mih::tlv_link_states_rsp(lsrl) & odtone::mih::tlv_link_descriptor_rsp(ldrl); m.tid(msg.tid()); _mihf.async_send(m); break; } case odtone::mih::request::link_configure_thresholds: { odtone::mih::link_cfg_param_list lcpl; msg >> odtone::mih::request() & odtone::mih::tlv_link_cfg_param_list(lcpl); odtone::mih::message m; // fill the status st = odtone::mih::status_failure; odtone::mih::link_cfg_status_list lcsl; m << odtone::mih::confirm(odtone::mih::confirm::link_configure_thresholds) & odtone::mih::tlv_status(st) & odtone::mih::tlv_link_cfg_status_list(lcsl); m.tid(msg.tid()); _mihf.async_send(m); break; } default: { odtone::mih::message m; st = odtone::mih::status_failure; m << odtone::mih::confirm(odtone::mih::confirm::capability_discover) & odtone::mih::tlv_status(st); _mihf.async_send(m); } } }
/** * 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()); } } } }
/** * Default MIH event handler. * * @param msg Received message. * @param ec Error code. */ void mih_user::event_handler(odtone::mih::message& msg, const boost::system::error_code& ec) { //yan-start-17/02/2012 //odtone::mih::message m; //m << odtone::mih::indication(odtone::mih::indication::link_get_parameters); //_mihf.sync_send(m); //yan-end if (ec) { log_(0, __FUNCTION__, " error: ", ec.message()); return; } //yan-start-17/02/2012 odtone::mih::link_tuple_id lid; odtone::mih::octet_string ifname; std::vector<link_info>::iterator it; std::vector<client_info>::iterator it_app; bool exist = false; msg >> odtone::mih::indication() & odtone::mih::tlv_link_identifier(lid); switch (msg.mid()) { case odtone::mih::indication::link_up: log_(0, "MIH-User has received a local event \"link_up\""); //log_(0, lid.addr); //_mihlid[_num_links] = lid; //++_num_links; exist = false; for (it = _mihlnks.begin(); it != _mihlnks.end(); ++it) { if (it->lid() == lid) { exist = true; break; } } if (!exist) { ifname = mih_get_ifname(lid); _mihlnks.push_back(link_info(lid, ifname)); for (it_app = _applist.begin(); it_app != _applist.end(); ++it_app) { //notify the applications that interface change occurs it_app->send_msg(_sockfd, ""); } } break; case odtone::mih::indication::link_down: log_(0, "MIH-User has received a local event \"link_down\""); for (it = _mihlnks.begin(); it != _mihlnks.end(); ++it) { if (it->lid() == lid) { _mihlnks.erase(it); for (it_app = _applist.begin(); it_app != _applist.end(); ++it_app) { //notify the applications that interface change occurs it_app->send_msg(_sockfd, ""); } break; } } /*int i; for (i = 0; i < _num_links; ++i) { if (_mihlid[i] == lid) { --_num_links; break; } } for (i = i + 1; i <= _num_links; ++i) { _mihlid[i-1] = _mihlid[i]; }*/ break; //yan-end case odtone::mih::indication::link_detected: log_(0, "MIH-User has received a local event \"link_detected\""); break; case odtone::mih::indication::link_going_down: log_(0, "MIH-User has received a local event \"link_going_down\""); break; case odtone::mih::indication::link_handover_imminent: log_(0, "MIH-User has received a local event \"link_handover_imminent\""); break; case odtone::mih::indication::link_handover_complete: log_(0, "MIH-User has received a local event \"link_handover_complete\""); break; } }