// This message is handled by the Link SAP. // // If this MIHF is the destination of the message, forward it to the // default Link SAP. If not then forward it to a peer MIHF. bool command_service::link_get_parameters_request(meta_message_ptr &in, meta_message_ptr &out) { log(1, "(mics) received a Link_Get_Parameters.request from", in->source().to_string()); if(utils::this_mihf_is_destination(in)) { // // Kick this message to MIH_Link SAP. // // The solution found to handle this corner case in the // 802.21 standard was to send the message, as is, to the // link sap. // // local_transactions was made to handle request's // from users to peer mihf's but in this case we add an // entry to handle the MIH_Link_Get_Parameters and // Link_Get_Parameters. // in->destination(mih::id("link")); _lpool.add(in); in->source(mihfid); _transmit(in); return false; } else { utils::forward_request(in, _lpool, _transmit); return false; } return false; }
// Check if there's a handler for this message and call it, else // discard message. void sac_dispatch::operator()(meta_message_ptr& in) { /** __no__ authentication at this point */ uint mid = in->mid(); log(1, "(sac) dispatching message with mid: ", mid); // // no thread safety because insertion should __only__ be made // on MIHF initialization // std::map<uint, handler_t>::iterator it; it = _callbacks.find(mid); if(it != _callbacks.end()) { handler_t process_message = it->second; meta_message_ptr out(new meta_message); out->tid(in->tid()); // send response if it was generated if (process_message(in, out)) _transmit(out); } else { log(1, "(sac) (warning) message with mid: ", mid, " unknown, discarding."); } }
// // Currently Command_Service messages are handled by a default local // user. If this MIHF is the destination of the message, check for a // pending transaction and forward the message. // bool command_service::generic_command_response(const char *recv_msg, const char *send_msg, meta_message_ptr &in, meta_message_ptr &out) { log(1, recv_msg, in->source().to_string()); if(utils::this_mihf_is_destination(in)) { // // Kick this message to default MIH User as an indication // log(1, send_msg); in->opcode(mih::operation::confirm); in->destination(mih::id("user")); // // source identifier is the remote MIHF // _transmit(in); return false; } else { utils::forward_request(in, _lpool, _transmit); return false; } }
// This message is handled by the Link SAP. // // If this MIHF is the destination of the message, forward it to the // default Link SAP. If not then forward it to a peer MIHF. bool command_service::link_actions_request(meta_message_ptr &in, meta_message_ptr &out) { log(1, "(mics) received a Link_Actions.request from", in->source().to_string()); if(utils::this_mihf_is_destination(in)) { // // Kick this message to MIH_Link SAP. // // The solution found to handle this corner case in the // 802.21 standard was to send the message, as is, to the // link sap. // in->destination(mih::id("link")); _lpool.add(in); in->source(mihfid); _transmit(in); return false; } else { utils::forward_request(in, _lpool, _transmit); return false; } return false; }
void _transmit() { if(sender_sendData() == ENC_COUNTER_WRAPAROUND) { handshakeState = SENDER_HELLO; while (HANDSHAKE_FINISHED != handshakeState) _handshake(); _transmit(); } }
// send message for all users subscribed to event from link identifier void event_service::msg_forward(meta_message_ptr &msg, mih::link_tuple_id &li, mih::event_list_enum event) { std::list<event_registration_t>::iterator it; int i = 0; // for logging purposes msg->source(mihfid); for(it = _event_subscriptions.begin(); it != _event_subscriptions.end(); it++, i++) { if ((it->event == event) &&(it->link == li)) { log(3, i, " (mies) found registration of user: "******" for event type ", event); msg->destination(mih::id(it->user)); _transmit(msg); } } }
/** * Link Get Parameters Response message handler. * * @param in The input message. * @param out The output message. * @return True if the response is sent immediately or false otherwise. */ bool command_service::link_get_parameters_response(meta_message_ptr &in, meta_message_ptr &out) { ODTONE_LOG(1, "(mics) received Link_Get_Parameters.response from ", in->source().to_string()); if(!_lpool.set_user_tid(in)) { ODTONE_LOG(1, "(mics) warning: no local transaction for this msg ", "discarding it"); return false; } ODTONE_LOG(1, "(mics) forwarding Link_Get_Parameters.response to ", in->destination().to_string()); _transmit(in); return false; }
// Check if there's a pending transaction and forward the message in // case there is. bool command_service::link_actions_response(meta_message_ptr &in, meta_message_ptr &out) { log(1, "(mics) received Link_Actions.response from ", in->source().to_string()); if(!_lpool.set_user_tid(in)) { log(1, "(mics) no local pending transaction for this message, discarding"); return false; } in->source(mihfid); log(1, "(mics) forwarding Link_Actions.response to ", in->destination().to_string()); _transmit(in); return false; }
// Check if there's a pending transaction and forward the message in // case there is. bool command_service::link_configure_thresholds_response(meta_message_ptr &in, meta_message_ptr &out) { log(1, "(mics) received Link_Configure_Thresholds.response from ", in->source().to_string()); if(!_lpool.set_user_tid(in)) { log(1, "(mics) warning: no local transaction for this msg ", "discarding it"); return false; } in->source(mihfid); log(1, "(mics) forwarding Link_Configure_Thresholds.response to ", in->destination().to_string()); _transmit(in); return false; }
// A peer MIHF sent a Event_Unubscribe.response, check if we have a // pending transaction with a local user. If so, then remove the // subscription of the user to the link and events that came in the // response. bool event_service::event_unsubscribe_response(meta_message_ptr &in, meta_message_ptr &) { log(1, "(mies) received Event_Unsubscribe.response from ", in->source().to_string()); // do we have a request from a user? if (!_lpool.set_user_tid(in)) { log(1, "(mics) warning: no local transaction for this msg ", "discarding it"); return false; } mih::status st; mih::link_tuple_id link; mih::event_list events; mih::message pin; // parse incoming message to (event_registration_t) reg *in >> mih::response() & mih::tlv_status(st) & mih::tlv_link_identifier(link) & mih::tlv_event_list(events); // remove subscription if (st == mih::status_success) st = unsubscribe(mih::id(in->destination().to_string()), link, events); log(1, "(mies) forwarding Event_Unsubscribe.response to ", in->destination().to_string()); // forward to user _transmit(in); return false; }
/** * Check if there is a handler for this message and call it, else * discard message. * * @param in The input message. */ void sac_dispatch::operator()(meta_message_ptr& in) { /** __no__ authentication at this point */ uint mid = in->mid(); ODTONE_LOG(1, "(sac) dispatching message with mid: ", mid); // // no thread safety because insertion should __only__ be made // on MIHF initialization // std::map<uint, handler_t>::iterator it; it = _callbacks.find(mid); if(it != _callbacks.end()) { handler_t process_message = it->second; meta_message_ptr out(new meta_message); out->tid(in->tid()); // send response if it was generated try { if (process_message(in, out)) _transmit(out); } catch(mih::bad_tlv) { ODTONE_LOG(1, "Discarding malformed message."); } catch(unknown_link_sap) { ODTONE_LOG(1, "Received message from an unknown Link SAP. Discarding message."); } catch(unknown_mih_user) { ODTONE_LOG(1, "Received message from an unknown MIH-User. Discarding message."); } } else { ODTONE_LOG(1, "(sac) (warning) message with mid: ", mid, " unknown, discarding."); } }
int main(int argc, char **argv) { size_t bufPos; size_t read; short buffer[BUFFERSIZE]; short encoded[BUFFERSIZE]; struct wavpcm_input input; struct wavpcm_output output; struct decode_chunk_struct decode_chunk_left; struct decode_chunk_struct decode_chunk_right; struct encode_chunk_struct encode_chunk_left; struct encode_chunk_struct encode_chunk_right; // Initializations srand(time(NULL)); _convFromOctets(); // Construct buffer_construct(); channel_construct(); sender_construct(); receiver_construct(); // Handshake #ifndef __ENC_NO_PRINTS__ printf("\n# Key Exchange\n"); printf("--------------\n\n"); #endif handshakeState = SENDER_HELLO; while (HANDSHAKE_FINISHED != handshakeState) _handshake(); // Transmit memset(&input, 0, sizeof(struct wavpcm_input)); input.resource = INPUTWAVFILE; memset(&output, 0, sizeof(struct wavpcm_output)); output.resource = OUTPUTWAVFILE; /* initialize structs */ memset(&encode_chunk_left, 0, sizeof(struct encode_chunk_struct)); memset(&encode_chunk_right, 0, sizeof(struct encode_chunk_struct)); memset(&decode_chunk_left, 0, sizeof(struct decode_chunk_struct)); memset(&decode_chunk_right, 0, sizeof(struct decode_chunk_struct)); /* initializing for quantisation */ encode_chunk_left.Qstep[0] = QSTART; encode_chunk_right.Qstep[0] = QSTART; decode_chunk_left.Qstep[0] = QSTART; decode_chunk_right.Qstep[0] = QSTART; encode_chunk_left.Qstep[1] = QSTART; encode_chunk_right.Qstep[1] = QSTART; decode_chunk_left.Qstep[1] = QSTART; decode_chunk_right.Qstep[1] = QSTART; encode_chunk_left.Qstep[2] = QSTART; encode_chunk_right.Qstep[2] = QSTART; decode_chunk_left.Qstep[2] = QSTART; decode_chunk_right.Qstep[2] = QSTART; encode_chunk_left.Qstep[3] = QSTART; encode_chunk_right.Qstep[3] = QSTART; decode_chunk_left.Qstep[3] = QSTART; decode_chunk_right.Qstep[3] = QSTART; wavpcm_input_open(&input); wavpcm_output_copy_settings(&input, &output); wavpcm_output_open(&output); for (bufPos = 0; bufPos < input.samplesAvailable ; bufPos += (BUFFERSIZE/2)) { read = wavpcm_input_read(&input, buffer); encode(buffer, &encode_chunk_left, &encode_chunk_right, encoded); while (buffer_isModified()) {} buffer_write((field_t *) buffer, BUFFERSIZE*sizeof(short)); _transmit(); receiver_receiveData(); buffer_read((field_t *) buffer, BUFFERSIZE*sizeof(short)); decode(&decode_chunk_left, &decode_chunk_right, encoded, buffer); wavpcm_output_write(&output, buffer, read); } wavpcm_output_close(&output); exit(EXIT_SUCCESS); }