From 0dfe264cc324d415b23b822f286cab120489143b Mon Sep 17 00:00:00 2001 From: djimmer Date: Mon, 1 Jun 2015 04:10:55 -0700 Subject: [PATCH] Added udp write file; Fixed the logging to the user a bunch; Still not managed to send a succesfull with proper result..; --- CLI/CLICommands.cpp | 21 +++++---------------- Control/L3CallControl.cpp | 21 +++++++++++---------- Control/L3MMLayer.cpp | 15 +++++++-------- udp_write.py | 29 +++++++++++++++++++++++++++++ 4 files changed, 52 insertions(+), 34 deletions(-) create mode 100755 udp_write.py diff --git a/CLI/CLICommands.cpp b/CLI/CLICommands.cpp index 1db3725..8c64d77 100644 --- a/CLI/CLICommands.cpp +++ b/CLI/CLICommands.cpp @@ -1083,7 +1083,7 @@ static CLIStatus endcall(int argc, char **argv, ostream& os) static CLIStatus testcall(int argc, char **argv, ostream& os) { - LOG(ALERT) << "Entering testcall function in CLICommands.cpp"; + //LOG(ALERT) << "Entering testcall function in CLICommands.cpp"; if (argc!=2) return BAD_NUM_ARGS; char *IMSI = argv[1]; if (strlen(IMSI)>15) { @@ -1099,29 +1099,18 @@ static CLIStatus testcall(int argc, char **argv, ostream& os) CALLINGPARTYBCDNUMBER */ - LOG(ALERT) << "Creating Transaction Entry"; + //LOG(ALERT) << "Creating Transaction Entry"; Control::FullMobileId msid(IMSI); Control::TranEntry *tran = Control::TranEntry::newMTC( NULL, msid, GSM::L3CMServiceType::TestCall, "0"); - LOG(ALERT) << "Created Transaction Entry"; + //LOG(ALERT) << "Created Transaction Entry"; - /* - // We just use the IMSI, dont try to find a tmsi. - FullMobileId msid(IMSI); - Control::TranEntry *tran = Control::TranEntry::newMTSMS( - NULL, // No SIPDialog - msid, - GSM::L3CallingPartyBCDNumber(srcAddr), - rest, // message body - string("text/plain")); // messate content type - Control::gMMLayer.mmAddMT(tran); - */ - //Control::initiateMTTransaction(transaction ,GSM::TCHFType,1000*atoi(argv[2])); - LOG(ALERT) << "Calling mmADDMT with: " << LOGVAR(tran); + //LOG(ALERT) << "Calling mmADDMT with: " << LOGVAR(tran); Control::gMMLayer.mmAddMT(tran); + os << "Starting UDP... please wait a few seconds" << endl; return SUCCESS; } diff --git a/Control/L3CallControl.cpp b/Control/L3CallControl.cpp index f21042d..b9c40d4 100644 --- a/Control/L3CallControl.cpp +++ b/Control/L3CallControl.cpp @@ -31,6 +31,7 @@ #include #include #include +#include namespace Control { @@ -1306,30 +1307,30 @@ void TestCallMachine::testCallStart(TranEntry *tran) //LOG(ALERT) << "Entering L3CallControl::CCBase::TestCall with transaction: " << LOGVAR(tran); // Mark the call as active. setGSMState(CCState::Active); - LOG(ALERT) << "Creating UDP Socket on port: " << gConfig.getNum("TestCall.Port"); + //LOG(ALERT) << "Creating UDP Socket on port: " << gConfig.getNum("TestCall.Port"); // Create and open the control port. UDPSocket controlSocket(gConfig.getNum("TestCall.Port")); - LOG(ALERT) << "Active UDP Socket on port: " << gConfig.getNum("TestCall.Port"); + //LOG(ALERT) << "Active UDP Socket on port: " << gConfig.getNum("TestCall.Port"); // FIXME -- Somehow, the RTP ports need to be attached to the transaction. // This loop will run or block until some outside entity writes a // channel release on the socket. - LOG(ALERT) << "Entering UDP test loop "; - + //LOG(ALERT) << "Entering UDP test loop "; + std::cout << "Done! UDP listening. Send STOP to break the loop.\n"; while (true) { // Get the outgoing message from the test call port. char iBuf[MAX_UDP_LENGTH] = {0}; int msgLen = (size_t)controlSocket.read(iBuf); - LOG(ALERT) << "iBuf is : " << LOGVAR(iBuf); + //LOG(ALERT) << "iBuf is : " << LOGVAR(iBuf); if(strcmp(iBuf, "STOP") == 0){ break; } - LOG(ALERT) << "Received " << msgLen << " bytes on UDP"; + //LOG(ALERT) << "Received " << msgLen << " bytes on UDP"; // Send it to the handset. GSM::L3Frame query(iBuf, msgLen); - LOG(ALERT) << " Sending L3Frame: " << LOGVAR(query); + //LOG(ALERT) << " Sending L3Frame: " << LOGVAR(query); channel()->l3sendf(query); // Wait for a response. @@ -1341,8 +1342,8 @@ void TestCallMachine::testCallStart(TranEntry *tran) break; } - LOG(ALERT) << "Received response from handset: " << LOGVAR(resp); - + //LOG(ALERT) << "Received response from handset: " << LOGVAR(resp); + std::cout << "Received from handset: " << LOGVAR(resp) << std::endl; // Send response on the port. unsigned char oBuf[resp->size()]; resp->pack(oBuf); @@ -1351,7 +1352,7 @@ void TestCallMachine::testCallStart(TranEntry *tran) delete resp; } - LOG(ALERT) << "Stopping L3CallControl::CCBase::Testcall function"; + //LOG(ALERT) << "Stopping L3CallControl::CCBase::Testcall function"; controlSocket.close(); channel()->l3sendm(L3ChannelRelease()); setGSMState(CCState::ReleaseRequest); diff --git a/Control/L3MMLayer.cpp b/Control/L3MMLayer.cpp index 8c7ba10..bc75361 100644 --- a/Control/L3MMLayer.cpp +++ b/Control/L3MMLayer.cpp @@ -237,7 +237,7 @@ MMUser::MMUser(string& wImsi) GSM::ChannelType MMUser::mmuGetInitialChanType() const { - LOG(ALERT) << "MMUser::mmuGetInitialChanType() started "; + //LOG(ALERT) << "MMUser::mmuGetInitialChanType() started "; devassert(gMMLock.lockcnt()); // Caller locked it. if (mmuMTCq.size()) { TranEntry *front = this->mmuMTCq.front(); @@ -252,9 +252,8 @@ GSM::ChannelType MMUser::mmuGetInitialChanType() const } } if (mmuTESTCALL.size()) { - LOG(ALERT) << "MMUser::mmuGetInitialChanType() inside mmuTESTCALL if"; + //LOG(ALERT) << "MMUser::mmuGetInitialChanType() inside mmuTESTCALL if"; return GSM::TCHFType; - //return GSM::SDCCHType; } devassert(mmuMTSMSq.size()); return GSM::SDCCHType; @@ -713,7 +712,7 @@ bool MMLayer::mmStartMTDialog(SipDialog *dialog, SipMessage *invite) void MMUser::mmuAddMT(TranEntry *tran) { - LOG(ALERT) << "Entering MMUser::mmuAddMT with" << LOGVAR(tran); + //LOG(ALERT) << "Entering MMUser::mmuAddMT with" << LOGVAR(tran); ScopedLock lock(gMMLock,__FILE__,__LINE__); // Way overkill. //ScopedLock lock(mmuLock,__FILE__,__LINE__); mmuPageTimer.future(gConfig.GSM.Timer.T3113); @@ -725,7 +724,7 @@ void MMUser::mmuAddMT(TranEntry *tran) mmuMTSMSq.push_back(tran); break; case L3CMServiceType::TestCall: - LOG(ALERT) << "Entering the L3CMServiceType::Testcall branch of the case+switch"; + //LOG(ALERT) << "Entering the L3CMServiceType::Testcall branch of the case+switch"; mmuTESTCALL.push_back(tran); break; default: @@ -852,7 +851,7 @@ RefCntPointer MMContext::mmGetTran(unsigned ati) const // After this, the RefCntPointer in mmcTE takes over the job of deleting the transaction when the last pointer to it disappears. void MMContext::mmConnectTran(ActiveTranIndex ati, TranEntry *tran) { - LOG(ALERT) << "mmConnectTran start with " << LOGVAR(ati) << " and: " << LOGVAR(tran); + //LOG(ALERT) << "mmConnectTran start with " << LOGVAR(ati) << " and: " << LOGVAR(tran); devassert(gMMLock.lockcnt()); // Caller locked it. // When a primary transaction is deleted we may promote the secondary transaction, so keep trying to make sure we delete them all: for (unsigned tries = 0; tries < 3; tries++) { @@ -1137,7 +1136,7 @@ bool MMLayer::mmTerminateByImsi(string imsi) // This is the way MMUsers are created from the SIP side. void MMLayer::mmAddMT(TranEntry *tran) { - LOG(ALERT) << "MMLayer::mmAddMT with: " << LOGVAR(tran); + //LOG(ALERT) << "MMLayer::mmAddMT with: " << LOGVAR(tran); LOG(DEBUG) <subscriberIMSI()); @@ -1145,7 +1144,7 @@ void MMLayer::mmAddMT(TranEntry *tran) // Is there a guaranteed tmsi? // We will delay this until we page in case an LUR is occurring right now. //if (uint32_t tmsi = gTMSITable.tmsiTabGetTMSI(imsi,true)) { mmu->mmuTmsi = /*tran->subscriber().mTmsi =*/ tmsi; } - LOG(ALERT) << "MMLayer::mmAddMT::mmu gives: " << LOGVAR(mmu); + //LOG(ALERT) << "MMLayer::mmAddMT::mmu gives: " << LOGVAR(mmu); assert(mmu); mmu->mmuAddMT(tran); } diff --git a/udp_write.py b/udp_write.py new file mode 100755 index 0000000..16b8ead --- /dev/null +++ b/udp_write.py @@ -0,0 +1,29 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- +import socket +import time +import binascii +from libmich.formats import * + +TESTCALL_PORT = 28670 +#len = 19 +#lai = 42 +#hexstr = "051a00f110" +#hexstr += "%02x%02x%02xfc" % (lai>>8, lai&255, (4*len+1)) +#hexstr += ''.join('%02x666666' % (4*i) for i in range(len)) +hexstr = "\x03\x3D" +print "layer3 message to be sent:", hexstr +#l3msg = binascii.hexlify(hexstr) +l3msg = hexstr; + +print "libmich interprets this as: ", repr(L3Mobile.parse_L3(l3msg)) + +tcsock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) +tcsock.settimeout(1) +try: + tcsock.sendto(l3msg, ('127.0.0.1', TESTCALL_PORT)) + reply = tcsock.recv(1024) + print "reply : " , reply + print "reply received: ", repr(L3Mobile.parse_L3(reply)) +except socket.timeout: + print "no reply received. potential crash?" \ No newline at end of file