[Users] Mbuni: getting MSISDN from Cisco AS5300 access server

2005-09-27 Thread Alexander Simakov

Hello Users!

Here is the story. I`m working in mobile telecommunications company.
We are using Kannel WAP and SMS gateway for serving our customers.
For some newer phones we also run squid http-proxy. WAP-aware phones
are served by our dedicated Cisco AS5300 network access server.

A few month ago we decided to run Mbuni MMS gateway. Almost everything
works good, but one problem: MSISDN! By default, incoming MMS messages
are signed with IP-address of sender, not the MSISDN. It is unacceptable 
for us.


Mbuni expects special http-header (X-WAP-Network-Client) to be set by 
Kannel.
This header contains user MSISDN. The Kannel configuration, in its turn, 
must

be RADIUS-aware. So, Kannel get`s MSISDN from the RADIUS server and passes
special http-header toward Mbuni.

Looks fine? But what about some newer phones, which use squid instead
of Kannel`s wapbox? Squid is unable to set a magic MSISDN header for us.

May be there is a better way to solve this problem (e.g. see Mbuni 
detokenizer

library), but I have my own. It consists of three pieces. They are

1. Patch for Mbuni 1.0.0
2. Tiny perl script with RSH Cisco commands
3. Snippet of Cisco configuration to work with Remote shell (RSH)

The main idea is very simple. Suppose that WAP-phone is currently
connected to the Cisco.

# show call calltracker active

This Cisco command shows active calls.
Command output (phone numbers are changed):

-- call handle=  2154 --
status=Active, service=PPP, origin=Answer, category=Modem
DS0 slot/port/ds1/chan=0/0/0/1, called=123, calling=123456789
userid=wap, ip=aaa.bbb.ccc.ddd, mask=0.0.0.0
setup=09/27/2005 15:01:59, conn=0.10, phys=22.77, service=36.59, 
authen=36.59

init rx/tx b-rate=33600/31200, rx/tx chars=193160/1155850
resource slot/port=1/47, mp bundle=0, charged units=0, account id=0
idb handle=0x61EED7E8, tty handle=0x619C4C84, tcb handle=0x0


We see that user with MSISDN '123456789' called the number 123.
User IP-address is aaa.bbb.ccc.ddd. This is exactly we want: mapping
between IP-address and MSISDN!

Using this patch, Mbuni will run RSH command 'show call calltracker active'
to find MSISDN of a user with a given IP-address.

To run RSH commands on Cisco you need something like this:

=8===
no ip rcmd domain-lookup
ip rcmd rsh-enable
ip rcmd remote-host Cisco_user aaa.bbb.ccc.ddd mbuni enable
=8===

First lines are used to enable RSH on Cisco.
Last line permits RSH for user 'mbuni' from host aaa.bbb.ccc.ddd.
Cisco_user is a valid user on Cisco NAS.

--
Good luck!
Alexander Simakov.



get_msisdn.pl
Description: Perl program
diff -Naur mbuni-orig/mmlib/mms_util.c mbuni-1.0.0/mmlib/mms_util.c
--- mbuni-orig/mmlib/mms_util.c 2005-07-26 08:44:58.0 +0400
+++ mbuni-1.0.0/mmlib/mms_util.c2005-09-12 17:10:51.0 +0400
@@ -26,6 +26,8 @@
 #include mms_queue.h
 #include mms_uaprof.h
 
+#define GET_MSISDN /usr/local/bin/get_msisdn.pl
+
 #define MAXQTRIES 100
 #define BACKOFF_FACTOR 5*60   /* In seconds */
 #define QUEUERUN_INTERVAL 15*60   /* 15 minutes. */
@@ -422,28 +424,30 @@
 }
 
 
-Octstr *mms_find_sender_msisdn(Octstr *send_url, List *request_hdrs, Octstr 
*msisdn_header, 
-  MmsDetokenizerFuncStruct* detokenizerfuncs)
+Octstr *mms_find_sender_msisdn(List *request_hdrs, Octstr *ip_header)
 {
- /* Either we have a WAP gateway header as defined, or we look for 
-  * last part of url, pass it to detokenizer lib if defined, and back 
comes our number.
-  */
- 
- Octstr *phonenum = http_header_value(request_hdrs, 
- msisdn_header);
- 
- if (!phonenum || octstr_len(phonenum) == 0) {
- List *l  = octstr_split(send_url, octstr_imm(/));
-
- if (l  list_len(l)  1) {
-  if (detokenizerfuncs) 
-   phonenum = detokenizerfuncs-mms_detokenize(list_get(l, 
list_len(l) - 1));
+ Octstr *ip = http_header_value(request_hdrs, ip_header);
+ Octstr *cmd = NULL, *msisdn = NULL;
+ FILE *fp;
+ char buf[4096];
+
+ info(0, Resolving user MSISDN);
+
+ cmd = octstr_format(%s %s, GET_MSISDN, octstr_get_cstr(ip));
+ info(0, Calling \%s\, octstr_get_cstr(cmd));
+ if ((fp = popen(octstr_get_cstr(cmd), r))) {
+ if (fgets(buf, sizeof buf, fp) != NULL) {
+  msisdn = octstr_create(buf);
+  octstr_strip_crlfs(msisdn);
  }
- if (l)
-  list_destroy(l, (list_item_destructor_t *)octstr_destroy);
+ pclose(fp);
  }
- 
- return phonenum; 
+ info(0, %s \%s\, returned msisdn = %s, 
+ fp ? Called : Failed to call, 
+ octstr_get_cstr(cmd),
+ msisdn ? octstr_get_cstr(msisdn) : null);
+ octstr_destroy(cmd);
+ return msisdn;
 }
 
 Octstr *mms_find_sender_ip(List *request_hdrs, Octstr *ip_header, 

Re: [Users] Mbuni: getting MSISDN from Cisco AS5300 access server

2005-09-27 Thread Paul Bagyenda

Alexander,

 This is very welcome indeed and am sure a lot of people will find  
it handy.


 I would suggest the following: This more properly fits within the  
detokenizer module framework. That is, one needs to add a library  
that one can call. It's arguments (passed in config file) would  
include the the path to the script, etc.


 The only gap so far is the detokenizer module is not being sent the  
client IP. This is easy to add (I shall do so in CVS). Your patch  
would then be an additional module (much like mms_detokenize_shell)  
that would do what you describe.


P.

On Sep 27, 2005, at 16:03, Alexander Simakov wrote:


Hello Users!

Here is the story. I`m working in mobile telecommunications company.
We are using Kannel WAP and SMS gateway for serving our customers.
For some newer phones we also run squid http-proxy. WAP-aware phones
are served by our dedicated Cisco AS5300 network access server.

A few month ago we decided to run Mbuni MMS gateway. Almost everything
works good, but one problem: MSISDN! By default, incoming MMS messages
are signed with IP-address of sender, not the MSISDN. It is  
unacceptable for us.


Mbuni expects special http-header (X-WAP-Network-Client) to be set  
by Kannel.
This header contains user MSISDN. The Kannel configuration, in its  
turn, must
be RADIUS-aware. So, Kannel get`s MSISDN from the RADIUS server and  
passes

special http-header toward Mbuni.

Looks fine? But what about some newer phones, which use squid  
instead
of Kannel`s wapbox? Squid is unable to set a magic MSISDN header  
for us.


May be there is a better way to solve this problem (e.g. see Mbuni  
detokenizer

library), but I have my own. It consists of three pieces. They are

1. Patch for Mbuni 1.0.0
2. Tiny perl script with RSH Cisco commands
3. Snippet of Cisco configuration to work with Remote shell (RSH)

The main idea is very simple. Suppose that WAP-phone is currently
connected to the Cisco.

# show call calltracker active

This Cisco command shows active calls.
Command output (phone numbers are changed):

-- call handle=  2154  
--

status=Active, service=PPP, origin=Answer, category=Modem
DS0 slot/port/ds1/chan=0/0/0/1, called=123, calling=123456789
userid=wap, ip=aaa.bbb.ccc.ddd, mask=0.0.0.0
setup=09/27/2005 15:01:59, conn=0.10, phys=22.77, service=36.59,  
authen=36.59

init rx/tx b-rate=33600/31200, rx/tx chars=193160/1155850
resource slot/port=1/47, mp bundle=0, charged units=0, account id=0
idb handle=0x61EED7E8, tty handle=0x619C4C84, tcb handle=0x0
-- 
--


We see that user with MSISDN '123456789' called the number 123.
User IP-address is aaa.bbb.ccc.ddd. This is exactly we want: mapping
between IP-address and MSISDN!

Using this patch, Mbuni will run RSH command 'show call calltracker  
active'

to find MSISDN of a user with a given IP-address.

To run RSH commands on Cisco you need something like this:

=8===
no ip rcmd domain-lookup
ip rcmd rsh-enable
ip rcmd remote-host Cisco_user aaa.bbb.ccc.ddd mbuni enable
=8===

First lines are used to enable RSH on Cisco.
Last line permits RSH for user 'mbuni' from host aaa.bbb.ccc.ddd.
Cisco_user is a valid user on Cisco NAS.

--
Good luck!
Alexander Simakov.


get_msisdn.pl
diff -Naur mbuni-orig/mmlib/mms_util.c mbuni-1.0.0/mmlib/mms_util.c
--- mbuni-orig/mmlib/mms_util.c2005-07-26 08:44:58.0 +0400
+++ mbuni-1.0.0/mmlib/mms_util.c2005-09-12 17:10:51.0  
+0400

@@ -26,6 +26,8 @@
 #include mms_queue.h
 #include mms_uaprof.h

+#define GET_MSISDN /usr/local/bin/get_msisdn.pl
+
 #define MAXQTRIES 100
 #define BACKOFF_FACTOR 5*60   /* In seconds */
 #define QUEUERUN_INTERVAL 15*60   /* 15 minutes. */
@@ -422,28 +424,30 @@
 }


-Octstr *mms_find_sender_msisdn(Octstr *send_url, List  
*request_hdrs, Octstr *msisdn_header,

-   MmsDetokenizerFuncStruct* detokenizerfuncs)
+Octstr *mms_find_sender_msisdn(List *request_hdrs, Octstr *ip_header)
 {
- /* Either we have a WAP gateway header as defined, or we look  
for
-  * last part of url, pass it to detokenizer lib if defined,  
and back comes our number.

-  */
-
- Octstr *phonenum = http_header_value(request_hdrs,
-  msisdn_header);
-
- if (!phonenum || octstr_len(phonenum) == 0) {
-  List *l  = octstr_split(send_url, octstr_imm(/));
-
-  if (l  list_len(l)  1) {
-   if (detokenizerfuncs)
-phonenum = detokenizerfuncs-mms_detokenize(list_get 
(l, list_len(l) - 1));

+ Octstr *ip = http_header_value(request_hdrs, ip_header);
+ Octstr *cmd = NULL, *msisdn = NULL;
+ FILE *fp;
+ char buf[4096];
+
+ info(0, Resolving user MSISDN);
+
+ cmd = octstr_format(%s %s, GET_MSISDN, octstr_get_cstr(ip));
+ info(0, Calling \%s\, octstr_get_cstr(cmd));
+ if ((fp = popen(octstr_get_cstr(cmd), r))) {
+  if