Skip to content

Commit

Permalink
Added udp write file; Fixed the logging to the user a bunch; Still no…
Browse files Browse the repository at this point in the history
…t managed to send a succesfull with proper result..;
  • Loading branch information
Djimmer committed Jun 1, 2015
1 parent 53b3642 commit 0dfe264
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 34 deletions.
21 changes: 5 additions & 16 deletions CLI/CLICommands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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;
}

Expand Down
21 changes: 11 additions & 10 deletions Control/L3CallControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include <GSMLogicalChannel.h>
#include <GSML3SSMessages.h>
#include <CLI.h>
#include <iostream>


namespace Control {
Expand Down Expand Up @@ -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.
Expand All @@ -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);
Expand All @@ -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);
Expand Down
15 changes: 7 additions & 8 deletions Control/L3MMLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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:
Expand Down Expand Up @@ -852,7 +851,7 @@ RefCntPointer<TranEntry> 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++) {
Expand Down Expand Up @@ -1137,15 +1136,15 @@ 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) <<this<<LOGVAR(tran);
{ ScopedLock lock(gMMLock,__FILE__,__LINE__);
string imsi(tran->subscriberIMSI());
MMUser *mmu = mmFindByImsi(imsi,true);
// 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);
}
Expand Down
29 changes: 29 additions & 0 deletions udp_write.py
Original file line number Diff line number Diff line change
@@ -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?"

0 comments on commit 0dfe264

Please sign in to comment.