Check Device’s User-Agent using Perl

There is a CPAN library that helps to parse the User-Agent. You can download the Perl library at:

http://search.cpan.org/~cmanley/Mobile-UserAgent-1.05/lib/Mobile/UserAgent.pm

After you download the library, perform the usual installation procedures:

perl Makefile.PL
make
make install

The following is the source code:


#!/usr/local/bin/perl
use strict;

use Mobile::UserAgent;
my $uaobj = new Mobile::UserAgent();

The codes above is the standard declaration so that you can call “Mobile::UserAgent” library. The following 3 lines are used for testing purposes. Uncomment the following 3 lines and comment the above 1 line to do some testing.


#my $useragent = 'Nokia6600/1.0 (4.09.1) SymbianOS/7.0s Series60/2.0 '.
#   'Profile/MIDP-2.0 Configuration/CLDC-1.0';
#my $uaobj = new Mobile::UserAgent($useragent);

The following lines check the User-Agent string and pass the output to the subroutine “printWml” if the device suppose WML or the subroutine “printHtml” if the device doesn’t.


if ($uaobj->success()) {
   my $out='Vendor: ' . $uaobj->vendor()     . "
\n"; $out.='Model: ' . $uaobj->model() . "
\n"; $out.='Version: ' . $uaobj->version() . "
\n"; $out.='Series60: ' . $uaobj->isSeries60() . "
\n"; &printWml($out); } else { &printHtml("Connecting Client is not a mobile user-agent \n"); }

Continue reading Check Device’s User-Agent using Perl

How to convert SI message to GSM SMS User Data

After publishing the article on “How to send WAP Push data through SMPP”, there is a lot of requests on how to formulate the GSM SMS User Data.

Basically, the following is an example in java with remark in the code to explain how this is done:

  public String toSmsBinary() {
    /**
     GSM SMS User Data
     06: UDH Length which is 6
     05: 16 bit address
     04: Length(4)
     0B84: Destination Port(2948)
     23F0: Source Port(9200)
     
     Wireless Session Protocol 
     90: Transaction ID
     06: PDU Type(Push)
     01: Headers Length is 1
     AE: Content-Type is application/vnd.wap.sic
     
     */
    StringBuilder ud = new StringBuilder().append("0605040b8423f0900601ae");
    ud.append(toWBXML());
    return ud.toString();

  }

The above function creates the GSM SMS User Data and Wireless Session Protocol (WSP) header. Continue reading How to convert SI message to GSM SMS User Data

How to send WAP Push data through SMPP

After publishing the article on “How to send WAP Push data through SMPP”, there is a lot of requests on how to formulate the GSM SMS User Data.

Basically, the following is an example in java with remark in the code to explain how this is done:

  public String toSmsBinary() {
    /**
     GSM SMS User Data
     06: UDH Length which is 6
     05: 16 bit address
     04: Length(4)
     0B84: Destination Port(2948)
     23F0: Source Port(9200)
     
     Wireless Session Protocol 
     90: Transaction ID
     06: PDU Type(Push)
     01: Headers Length is 1
     AE: Content-Type is application/vnd.wap.sic
     
     */
    StringBuilder ud = new StringBuilder().append("0605040b8423f0900601ae");
    ud.append(toWBXML());
    return ud.toString();

  }

The above function creates the GSM SMS User Data and Wireless Session Protocol (WSP) header. Continue reading How to send WAP Push data through SMPP

Example to read MMS message and write to a file in Perl

This example is a simple subroutine to check whether the content is a MMS and write to a file. Combine the example in “Detect WAP browser and redirect to different url in Perl”, you can route the URL request to another URL if it is not a MMS content.

The subroutine “doRedirrect” is meant to do that, or you can do a simple print message to state that this requested URL is for MMS.

The following is the code for this:


sub doMMSC {
   my $class=shift;

   my $length = $ENV{'CONTENT_LENGTH'};

   if ($ENV{'CONTENT_TYPE'} ne "application/vnd.wap.mms-message") {
      &doRedirrect;
      return;
   }
   

   my $count = read(STDIN, $body, $length);
   if ($count == $length) {
      open ER, ">incoming.mms";
      print ER $body;
      close ER;    
   }

}

What is MM per second (MM/sec)?

What is MM per second (MM/sec)? How do you calculate MM per second?

MM/sec is a common term that Telco industry used to define the license scheme when they measure the performance of MMSC (Multimedia Messaging Service Centre). So how do the Telco industry comes up with MM/sec? It first starts with SMSC when Telco industry starts to measure SMSC and this is how SMS/sec first used. When the industry inverts MMS and start to measure performance of MMSC, MM/sec is been used.

However, measuring SMS is easier since 1 SMS is 160 characters and if a SMS message is more than 160 characters, it is treated as multiple SMS. In additional, traditional SMSC is just a simple stored and forward server for SMS.

Due to the complexity of what MMSC can do and message size per message; it is sometime very difficult to compare Apple to Apple between different MMSC if we are going to compare MM/sec. For example, to send and retrieve a 100KB of MM, it will definitely take longer to send and retrieve a 10KB of MM. Complexity will come into the equation if you start to take re-try push scheme, multiple recipients, delivery and read-reply report into the consideration. With add-on features such as transcoding and copy-forwarding become a standard feature that can be found in MMSC, it is quite hard to measure MM/sec.

For such, when speaking to different people in the Telco industry, different people has different idea what they think MM/sec is about and for such, it is very important to understand their presumption is.

Anyway, the following is what I believe a MM/sec should be:

1. Any incoming MM submission and retrieval that come in and out of the MMSC except notification push request should be treated as one MM.
2. Multiple push requests should not be treated as multiple MM if the recipient is only downloading one MM.
3. Request with does not contain the message’s content such as Read-Reply Report should be ignored.

In short, each full cycle of MM submission and retrieval will consist of at least two MM.

How to cut a 1GBit Ethernet Crossover RJ45 Cable

This following table shows the arrangement of Cable for 1GBit Ethernet Crossover Cable which used all the 8 wires:

GIGABIT ETHERNET (1000BASE-T) CROSSOVER
Plug A Plug B
Pin # Signal Conductor Color Code Pin # Signal Conductor Color Code
1 BI_DA+ white/green 1 BI_DA+ white/orange
2 BI_DA- green 2 BI_DA- orange
3 BI_DB+ white/orange 3 BI_DB+ white/green
4 BI_DC+ blue 4 BI_DC+ white/brown
5 BI_DC- white/blue 5 BI_DC- brown
6 BI_DB- orange 6 BI_DB- green
7 BI_DD+ white/brown 7 BI_DD+ blue
8 BI_DD- brown 8 BI_DD- white/blue

Detect WAP browser and redirect to different url in Perl

Do you want to have the same url for your Web and Wap broswer? The following is the code to do so in Perl:


#!/usr/local/bin/perl
use CGI;

my $query = new CGI;

my @list=$query->Accept();

my $htmlsite="http://www.artofmobile.com/index.html";
my $wmlsite="http://www.artofmobile.com/index.wml";

my $wml=0;
my $html=0;

foreach (@list) {
   $html=1 if /text\\/html/i;
   $wml=1 if  /wap/;
}


print $query->redirect($wmlsite)  if $wml==1;
print $query->redirect($htmlsite) if $html==1;
print $query->redirect($wmlsite);

How to create a WAP push service in Perl

To push a service (or commonly a URL) to a mobile phone from a Push Initiator (PI), normally a web server, WAP defines a protocol to do so in Push Access Protocol (PAP).

This Push Message can be sent either as Service Indication (SI) or Service Loading (SL) kind of service push.

SI signals an event on which the client should get informed when a message is pushed to the mobile device. The user can base of the text message to decide whether to retrieve it or not. SL push service was specified so that a PI can push a URL to the mobile device which is automatically loaded and executed.

The following covers Perl code to do both SI and SL service. The Perl code is the same, you just need to load different raw file to achieve the different kind of Push Message.


#!/usr/local/bin/perl

use LWP::UserAgent;

my $ua = LWP::UserAgent->new;
$ua->agent("MyApp/0.1 ");

my $req = HTTP::Request->new(
   POST => 'http://127.0.0.1:9004/pushservice');

$req->content_type('multipart/related; type="application/xml"; '.
   'boundary="boundary0123456789"');

open(FILE, "raw") or die "$!";
my $content=;
close FILE;


$req->content($content);
print "----Header-----\n";
$hash=$req->headers;
# print $hash->as_string;
print "\n----Body-------\n";
print $req->content;

my $res = $ua->request($req);
if ($res) {
   # Check the outcome of the response
   if ($res->is_success) {
      my $ret= $res->content;
      print "$ret\n";
   } else {
      print "\n".$res->status_line, "\n";
      print $res->content;
      print "\n";
   }
} else {
   print "No pointer assigned\n";
}

print "\n\n";

Input file for SI push (raw_si):


--boundary0123456789
Content-Type: application/xml





--boundary0123456789 Content-Type: text/vnd.wap.si Welcome to Art of Mobile! --boundary0123456789--

Input file for SL push (raw_sl):


--boundary0123456789
Content-Type: application/xml





--boundary0123456789 Content-Type: text/vnd.wap.sl --boundary0123456789--