Handling %xx (special characters escaped in url) in Django apps

These days I’m working on django application which will be processing binary data, encoded in %xx (quoted hex), via GET url request.
Lets look at a sample url:

http://mosms.senthadev.com/submit/?udh=%02q%00&ud=%00%0B%0A%B0%00%01%00%00%00%00%12%00%01

To retrieve the url GET params, I used following method:
ud = request.GET.get(‘ud’)
udh = request.GET.get(‘udh’)

And I have convert the ud and udh to hex string (e.g. 027100). But, these variables currently holding the values as ascii.

print('%r' % ud) => u'\x02q\x00'
print('%r' % udh) => u'\x00\x0b\n\ufffd\x00\x01\x00\x00\x00\x00\x12\x00\x01'

But, I faced an error when I tried to convert it using : binascii.b2a_hex(ud)
Because, Django threw the following error:

UnicodeEncodeError: ‘charmap’ codec can’t encode character u’\ufffd’ in position 3: character maps to

Interesting problem. But, I was running out of time. So, I got down little lower and found another alternative solution.

This is the solution I used:

import urllib, binascii
from django.http import HttpResponse

def submit():
    #collecting the get params into dict
    data = dict(item.rsplit('=') for item in request.META['QUERY_STRING'].rsplit('&'))
    udh = str(binascii.b2a_hex(urllib.unquote(data['udh'])))
    ud = str(binascii.b2a_hex(urllib.unquote(data['ud'])))

    #now I have the ud, udh as proper hex string to be stored in db.
    #udh : 027100
    #ud : 000b0ab0000100000000120001

Thank you stackoverflow for 1 line code to parse the url params into dict()

Why I’m moving away from RabbitMQ

Some weeks back, I was working on a prototype to migrate an existing Jboss/JMS based solution to RabbitMQ/Spring based solution. Why? because to utilize the AMQP (wire based protocol) functionality and remove the JMS (API based) dependency. Therefore django/python web framework can post the requests in JSON and doesn’t need to communicate via JMS. While developing with RabbitMQ and spring-amqp, I came across following issues which made me to move away from RabbitMQ. Some issues are totally depends on the business requirement.

1. Need ‘Message Delay’ functionality

This is a important business requirement for us. Say, when a customer orders a service, first we send a instruction details in text SMS and then we send the 2nd detail SMS after 2 mins delay rather than sending both SMS’s at once. This gives some time for the users to read it. Once the django webapp submits the request via Queue, we process it, create two SMS’s ( one with 2 mins delay) and submit them to another Queue which handles the delivery. Now, by design, its not possible to set the delay on the messages when submitting to the RabbitMQ. It was designed to send the messages quickly than delaying it.

I could use the java sdk build-in ‘DelayQueue’ and submit the messages to RabbitMQ, but then I would be missing the durability or have to re-invent the wheel.

2. Dead Letter Queue (DLQ) functionality for durable queue

DLQ is a secondary queue to store the messages which wasn’t able to process by the consumer due to some errors.
Spring-amqp provides two ways to return a message back to RabbitMQ/DLQ.

(a) Throw a AmqpRejectAndDontRequeueException, this will store the message in DLQ.
(b) Set the ‘org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer’ property ‘defaultRequeueRejected’ to ‘false’.

Sample spring configuration xml,

       <rabbit:queue id="smsGatewayQueue" durable="true" auto-delete="false" exclusive="false" name="SmsGatewayQueue">
		<rabbit:queue-arguments>
		    <entry key="x-dead-letter-exchange" value="messagingExchange.DLQ" />
		</rabbit:queue-arguments>
	</rabbit:queue>

While testing it, I made some errors to test the DLQ functionality.
But, I’m unable to view/retrieve any messages from DLQ. Couldn’t figure out what happened to those messages.

After following falls, decided to use the Amazon SQS.
It provides the delay functionality what I needed. But there is a catch. Have to use the polling to check for new messages and implement logic to avoid duplicate messages from the SQS.

Will let you know the SQS outcome.

Using spring-amqp to access RabbitMq

These days I’m working on re-engineering our existing messaging platform. One of our messaging platform’s main functionality is to connect with different external SMS Gateway providers and submit the sms messages. Existing platform was build on top of Jboss Messaging Queue /MDB. In the process of re-engineering, platform should use RabbitMQ as a new broker to store the messages before processing. RabbitMQ is based on wire protocol and Jboss Messaging framework is based on Java JMS API. Reason for switching is that messaging producers are build on django/python and it wants to submit request using JSON. Instead of writing a python JMS communication, I want utilize the  AMQP (Advanced Messaging Queue protocol ). Currently rabbitMQ is known for amqp implementation and of course, it is build on erlang and is robust. Lets look into details.

1. Using spring-amqp 1.1.2.RELESE to access rabbitMQ. Spring-amqp abstracts the AMQP provider, therefore we can change the broker easily. Using following maven dependency:

<dependency>
   <groupId>org.springframework.amqp</groupId>
   <artifactId>spring-amqp</artifactId>
   <version>1.1.2.RELEASE</version>
</dependency>
<dependency>
   <groupId>org.springframework.amqp</groupId>
   <artifactId>spring-rabbit</artifactId>
   <version>1.1.2.RELEASE</version>
   </dependency>
<dependency>
   <groupId>com.rabbitmq</groupId>
   <artifactId>amqp-client</artifactId>
   <version>2.8.7</version>
</dependency>

2. Spring-amqp web site documentation specifics version 1.1.1, but 1.1.2 includes a fix for the transaction support. We have to include spring-rabbit, it contains the rabbitMQ specific implementation and utilizes the com.rabbitmq library.

3.  Brief look into rabbitMQ. Producers uses the ‘Routing’ and connects to the ‘Exchange’ to submit the messages. ‘Queue’s are connected to ‘Exchange’ using ‘Binding’. Consumers connects to ‘Queue’ and receives the messages and process it. Consumers could receive the messages synchronously and/or asynchronously. We’ll be using async to receive the messages from the broker.

4. Using following spring configuration xml.

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:rabbit="http://www.springframework.org/schema/rabbit"
       xmlns:aop="http://www.springframework.org/schema/aop"
       xmlns:tx="http://www.springframework.org/schema/tx"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
                           http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
                           http://www.springframework.org/schema/rabbit
                           http://www.springframework.org/schema/rabbit/spring-rabbit.xsd
                           http://www.springframework.org/schema/tx
                           http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
                           http://www.springframework.org/schema/aop
                           http://www.springframework.org/schema/aop/spring-aop-3.0.xsd" ></code>

<bean id="rabbitConnectionFactory" class="org.springframework.amqp.rabbit.connection.CachingConnectionFactory">
<constructor-arg index="0" value="localhost" />
<constructor-arg index="1" value="5672" />
<property name="username" value="guest" />
<property name="password" value="guest" />
<property name="channelCacheSize" value="10"/>
</bean>

<rabbit:queue id="requestQueue" durable="true" auto-delete="false" exclusive="false" name="RequestQueue"/>
<rabbit:queue id="smsGatewayQueue" durable="true" auto-delete="false" exclusive="false" name="SmsGatewayQueue"/>

<rabbit:direct-exchange name="messagingExchange" durable="true" auto-delete="false" id="PlatformExchange">
<rabbit:bindings>
<rabbit:binding queue="SmsGatewayQueue" key="SmsGatewayQueue"/>
<rabbit:binding queue="RequestQueue" key="RequestQueue"/>
</rabbit:bindings>
</rabbit:direct-exchange>

<bean id="requestTemplate" class="org.springframework.amqp.rabbit.core.RabbitTemplate">
<property name="connectionFactory" ref="rabbitConnectionFactory"/>
<property name="exchange" value="PlatformExchange"/>
<property name="queue" value="RequestQueue"/>
<property name="routingKey" value="RequestQueue"/>
<property name="messageConverter">
<bean class="org.springframework.amqp.support.converter.JsonMessageConverter"></bean>
</property>
</bean>

<bean id="smsGatewayTemplate" class="org.springframework.amqp.rabbit.core.RabbitTemplate">
<property name="connectionFactory" ref="rabbitConnectionFactory"/>
<property name="exchange" value="PlatformExchange"/>
<property name="queue" value="SmsGatewayQueue"/>
<property name="routingKey" value="SmsGatewayQueue"/>
<property name="messageConverter">
<bean class="org.springframework.amqp.support.converter.JsonMessageConverter"></bean>
</property>
</bean>

<!-- Containers -->
<bean id="requestContainer" class="org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer">
<constructor-arg ref= "rabbitConnectionFactory" />
<property name="concurrentConsumers" value="4" />
<property name="messageListener" ref="requestHandler" />
<property name="queues" ref="RequestQueue" />
<property name="channelTransacted" value="true" />
<property name="autoStartup" value="true" />
</bean>

<bean id="smsGatewayContainer" class="org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer">
<constructor-arg ref= "rabbitConnectionFactory" />
<property name="concurrentConsumers" value="4" />
<property name="messageListener" ref="smsGatewayHandler" />
<property name="queues" ref="SmsGatewayQueue" />
<property name="channelTransacted" value="true" />
<property name="autoStartup" value="true" />
</bean>

<!-- message listeners -->
<bean id="requestHandler" class="com.senthadev.RequestHandler" />
<bean id="smsGatewayHandler" class="com.senthadev.SmsGatewayHandler" />

<!-- rabbit mq broker admin -->
<bean id="rabbitAdmin" class="org.springframework.amqp.rabbit.core.RabbitAdmin">
<constructor-arg ref="rabbitConnectionFactory" />
</bean>

<bean id="rabbitTxManager" class="org.springframework.amqp.rabbit.transaction.RabbitTransactionManager">
<property name="connectionFactory" ref="rabbitConnectionFactory"/>
</bean>

<tx:annotation-driven transaction-manager="rabbitTxManager"/>

</beans>

5.  Following Java code is a sample producer, it will use RabbitTemplate to submit the message.

package com.senthadev;

import java.util.HashMap;
import org.apache.log4j.Logger;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessageProperties;

public class RequestDB {
    private static final Logger log = Logger.getLogger(MootaDB.class);

    public static void main(String a[]) throws Exception{
        ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("classpath:spring-context.xml");
        AmqpTemplate requestTemplate = (AmqpTemplate)ctx.getBean("RequestTemplate");

        while (true){
            RequestDto req = new RequestDto();
            //Converts the RequestDto to json using org.codehaus.jackson
            requestTemplate.convertAndSend(req);
            Thread.sleep(1000);
        }
    }
}

6. Following Java code is a sample async consumer, it will be used by SimpleMessageListenerContainer to processes the messages.

package com.senthadev;

import org.apache.log4j.Logger;
import org.codehaus.jackson.map.ObjectMapper;
import org.springframework.amqp.AmqpException;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessageListener;
import org.springframework.amqp.core.MessageProperties;

public class RequestHandler implements MessageListener{

    private static final Logger log = Logger.getLogger(RequestHandler.class);

    @Override
    public void onMessage(Message message) {
        try{
        ObjectMapper convert = new ObjectMapper();
        RequestDto data = convert.readValue(message.getBody(), RequestDto.class);

        AmqpTemplate smsgwTemplate = (AmqpTemplate)SpringLoader.instance().getBean("smsGatewayTemplate");
        SmsMesgDto smsDto = factory.buildSms(data);
        smsgwTemplate.convertAndSend(smsDto);
        }catch (Exception e){
            log.error(e);
            throw new AmqpException(e);
        }
    }
}

7. According to the spring configuration, consumer container (requestContainer) will use 4 threads to process the messages from rabbitmq. When a message is received, it will call ‘RequestHandler’ to process it. Remember to write thread safety code.

8. Limitation that I’m facing now is that in JMS/Jboss its possible to set a delivery delay for the messages. Means, we can set a delivery time for the messages and the container will deliver the message to the consumer when the delivery delay is arrived. But in rabbitMQ its not possible to set a delivery delay. I have to find a technique to achieve delivery delay. Spring-amqp/Container provides methods to start and stop the container operations. Have to use them to achieve the delivery delay functionality. (Will be covering that soon.)

I have described the steps in high level. I will be adding a sample project in github soon.

Meetup about agile and architecture

Today, I attended the XP oslo meetup about “The conflict between agile and architecture – myth or reality? “. It was a good meetup where I was able learn some interesting concepts. This is what I understood after the meetup.

  1. Agile is about delivering functionality in short iterations (say every 2 weeks). It doesn’t focus on full blown architecture/plan. It takes a segment of the entire proposed application, deliver it, and iterate it until its OK and then move to other segments. In agile team, all team members wears the hat as a architect/leader/janitor/developer. Its most suits to self organized team. It doesn’t care about UML diagrams or complete overall architecture diagrams (documentation similar to telephone directory).
  2. But, agile needs architecture. Because architecture makes sure that all the team members are walking on the same path. The path leads to what customer wants or willing to adopt it (apple style). It doesn’t mean that agile needs complete UML diagrams, but it needs the necessary diagrams (say sequence disgram, component diagram) to explain someone who wants to save the project in the middle or maintain the project.
  3. Chaos team needs a dedicated architect/mentor/janitor to make sure the team is walking on the correct path. The person should have skills ‘T’. ‘|’ Deep knowledge on the technologies and “__” breadth knowledge on the business processes.
  4. Its better to start with the skeleton system (max 1 month time) and then continue the agile iterations. Skeleton system is about defining the boundaries, identifying the functional/technical risk factors, high level/minimalists  architecture design to picture the overall system, prototypes etc.
  5. Communication is very important. There is no questions as stupid questions
  6. If you are an architect, dive deep until you get the confidents on the your architecture. And fight for your architecture if someone wants to change it. Without a fight no change.
  7. Identified a new term “Onion architecture”. Its used when the project is based on RnD. Have to dig deep to learn more about it.
  8. What you need to start the architecture? paper and pencil/pen to start decoding the usecases.
  9. Architect should be part of the development team rather than external person who produces dictionary size documents.

For me, if a person can explain what he/she understood through diagrams/flowchart, thats means the person knows what he/she going to produce. Simply 50% of the war is won.

Replacing a SMS which is already been sent

Lets take a scenario to explain the topic,

Company VirtualA has implemented a 2 step authentication using SMS for their web application. When a end-user provides his/her login credentials, system will send a SMS with a single use token. And end-user has to enter the received token to start using application. Now these SMS’s will be filling the end-users mobile phone. What if we want to replace an existing SMS with the new token? and end-users mobile phone will always have 1 SMS with the last received token. How can we achieve this:

According the 3Gpp TS 23.040 specification (which is a technical realization of a SMS ), we can set the TP-PID field bits to achieve the sms replacement. We must note that this feature is optional. Which means Mobile OS/(U)SIM has to implement this feature as mentioned in the 3gpp specification. Well, most mobile will support it. (Should test this feature on IOS 6)

TP-PID (TP-Protocol Identifier) says,

When bit 7 = 0, bit 6 = 1 and rest of the bits 5..0 are used as defined below:

01000000 (0x40)- Short message type 0 (This is the normal text sms)
01000001 (0x41) - Replace short message type -1
01000010 (0x42) - Replace short message type -2
01000011 (0x43) - Replace short message type -3
01000100 (0x44) - Replace short message type -4
01000101 (0x45) - Replace short message type -5
01000110 (0x46) - Replace short message type -6
01000111 (0x47) - Replace short message type -7

This means we can have 7 replaceable sms, for example sending a long sms (more than 160 characters).

How does the Mobile identifies the previous sms to replace with the new received sms. It will use the originating address + pid value combination to replace.

For example, this VirtualA uses 27000 as a originating address to send the token SMS. And their using Kannel to send the SMS.


http://token.viruala.io:12000/cgi-bin/sendsms?username=xx&password=xx&from=27000&to=47xxxxxxx&smsc=toekn&coding=0&pid=65&text=124323

parameter ‘pid’ represents the TP-PID, and its value is 65 means its using the type-1 replacement.

User will receive the SMS.

and if we send it again with the new token


http://token.viruala.io:12000/cgi-bin/sendsms?username=xx&password=xx&from=27000&to=47xxxxxxx&smsc=toekn&coding=0&pid=65&text=tgr435

Now the mobile will replace existing message with this new token. And uses mobile will still have 1 sms.

If a SMSgateway provider provides an option to set this PID, then its possible to use this feature.

SIM card provisioning via Over-the-Air 2

In this part, we’ll be looking into more details of remote APDU (Application Protocol Data Unit). Remote APDU’s are set of commands which are send over the air to manage the files and applications on the smart cards (UICC). Technical specification are from  3gpp TS 31.101 (UICC terminal interface and physical structure), TS 31.102 (Characteristics of the USIM application) and ETSI TS 102 226. TS 31.102 explains about the file structure, contents of elementary file (EF) and application protocol used between USIM and mobile equipment. We’ll be looking into application protocol, in other word, it is a structure describing how to pack the instructions and parameters to manage USIM cards.

According to the previous part, we want to update the EF_SPN file on the (U)SIM application. To invoke this change, we have to issue 4 sequence of APDU commands. The sequence of commands as follows:

A0A40000023F00A0A40000027F20A0A40000026F46A0D60000110153656e746861FFFFFFFFFFFFFFFFFFFF

Each command contains below given structure:

(Above diagram is taken from 3gpp TS 31.101 specification)

Lets look into the 1st APDU : A0A40000023F00

A0 – Its the CLA. Its means thats the bits are coded as 7816-4 and no secure messaging between card and the terminal

A4 – Its the Instruction code. Its means ‘SELECT’ following file/directory

00 – Its the P1 parameter. 00 indicates that P1 is not used. P1 is not used for EF_SPN update.

00 – Its the P2 parameter. 00 indicates that P2 is not used.

02 – its the Lc . Number of bytes in the ‘data’ field.

3F00 – its the data field. Its the MF file id.

This commands is to select the MF (Master File)

Next APDU :  A0A40000027F20

This command is to select the DF (GSM), file id = 7F20

Next APDU :  A0A40000026F46

This command is to select the EF (SPN), file id = 6F46

Last APDU : A0D60000110153656e746861FFFFFFFFFFFFFFFFFFFF

A0 – Its CLA.

D6 – Its a instruction byte for UPDATE BINARY

00 – P1 is not used

00 – P2 is not used

11 – bytes of the ‘data’ (its 17 bytes or ox11 bytes)

0153656e746861FFFFFFFFFFFFFFFFFFFF – data

This will simply update the content of the file with this value.

thats it.

If we look at the EF_SPN file structure (This and other file structures are defined in TS 31.102 and TS 31.101)

This binary (transparent) file contains the service provider name and appropriate requirement for the display on the Mobile equipment.

File Identifier = 6F46

File size = 17 bytes

1 byte = display option, in our example its ’01’ : which says that it must be displayed.

2 to 17 byte (16 bytes length) = Contains the service provider name and unused space must be padded with ‘FF’. Characters should be gsm default 7-bit charset or UCS2. In our example, name =  53656e746861 (which is Sentha) , and the unused spaces are filled with ‘FF’.

USIM has 3 different type of file : they are binary, linear record and cyclic records.

In the next part (part 3), we’ll look into how we going to pack this APDU command strings in a SMS.

Sending bulk SMS using kannel

How could we use kannel SMS gateway to send bulk MT sms.

1. Kannel bin directory has a console app called mtbatch. Its executed by providing content-file and receivers-file.

“Content- file” contains the  sms text message which needs to be send. Entire content will be send as a single sms (If the sms is long then it will be spilt and send).

“Receivers-file” contains the ‘\n’ (new line separated) mobile numbers.

Sample command:

/usr/local/kannel/bin/mtbatch -b bearerbox.host.com -p 13001 -r smsc_id -f bulk_sender content.txt receiver.txt

There are more options,  just invoke mtbatch without file arguments and it will display all available options.

This approach directly connects to bearer box without going through the smsbox. Simply no need of http request. Its not possible to directly send multiple messages to multiple recipients (n x n). Only 1 message to n recipients. We can write a python module to invoke this mtbatch for n x n. And its only possible to send text messages and no binary messages. And not possible to set the delivery report flags and link.

2. Enable the kannel store configuration,

store-type = file
store-location = “/usr/local/kannel/log/k_mt.store”
store-dump-freq = 10

and send the bulk messages vi http request.

Maybe use a external queue to store the messages and call the kannel http to send sms. I like this approach. I have the option to send text as well binary bulk sms to the multiple recipients.

3. I was reading about Kannel SQLbox. Kannel embedd with rdbms to handle the sms. So, bulk sms request could send via sql statements rather than http. But I haven’t tried this approach.

Birkebeinerløpene 2012

Today I ran the Birkebeinerløpet (21 km) 2012 in lillehammer. It was another fantastic forest run. I was happy with the event organization. They were providing bus travel all the way from lillehammer station to the starting place. Well I took 1:56 hours to complete the run, should have done better ;) . Those 2 hours, all my focus was on the path. From starting to end, path contains bushes/grass, stones, mud, creek, roots and it was very slippery. I should have used the trail shoes. But I want to try my adidas adizero running shoes. Well it saved me from certain rocks. But when on mud :) I have to slow down and slide . First 7 km was tiring and a lot of heavy breathing. After that I was in zone until finish line. I was thinking nothing. My eyes were feeding information to my brain and brain was controlling the foot placement. Simply System1 was switched on.

I’ll see you next year.

SIM card provisioning via Over-the-Air 1

These days I’m developing an API for performing SIM card provisioning. Sim card provisioning is about how an operator wants to manage their subscribers SIM remotely. Even though we generally call it SIM, its actually technically called UICC (Universal Integrated Circuit Card). This UICC has one applet or application called SIM (Subscriber Identity Module). This SIM allows the mobile user to use the operators network. Well, this SIM module contains the encryption keys and other important data. These days its possible to have more than one SIMs in one UICC. Simply it means that we can have more than one subscriptions in the SIM card and phone can automatically switch (well its via Sim Toolkit Application) to correct network depending on the settings :) .

These SIM/UICC card contains important details and its needs to managed securely. When its comes to management, its all about provisioning the SIM via Over-the-Air, simply remotely without disturbing the end-user. There are 2 kind of provisioning. They are :

  1. RFM (Remote File Management)
  2. RAM (Remote Applet Management) (This is where Java card comes)

Say, for example, every SIM module contains SMSc number. A mobile phone uses this smsc number internally when we send a SMS to someone. Now operator wants to update this number for their subscribers. So they will be using the RFM approach. It can be done via SMS, Cell broadcast service (CBS) and Bearer independent protocol (BIP). Currently I’m using SMS delivery mechanism. This approach is described in 3Gpp TS 23.048 and TS 31.102 / TS 51.011 specification.

Ok, back to the Topic. UICC manufactures designed the SIM in way that it can be only managed securely unless some operators disabled these security measure. These security measures are: Secure command encryption, redundancy checksum (crc32, cryptographic checksum, etc) and counter mechanism to stop the execution of the previously executed command. Every SIM’s module has Minimum Security Level (MSL), which says thats secure command (technically APDU) should satisfy specified security measurement. Every SIM module contains 3 types of keys. They are KiC, KiD and KiK. Each keys type has 1 or more key set.

  1. KiC : This is used for encryption. Thats is used to encrypt the secure command. Generally it uses the 3DES CBC mode with 2 keys. Therefore this KiC is a 16 bytes length. We split the key into 8 bytes and use it for 3DES.
  2. KiD: This is used for generating the cryptographic checksum. Its used to make sure that command is from valid identity and not tampered.
  3. KiK: If the KiC or KiD are compromised, then its needs to be changed. Then we used  this master key to change other keys.
  4. To generate a simple 4 bytes redundancy check, we use the Crc32 algorithm
  5. Mostly the algorithms are standard. But its possible to use different algorithm. Its depends on the uicc manufacturer and operator.

Secure commands are use to perform some management operations on the SIM. Lets say we want to update the EF_SPN file. Its file which contains the operators name. The name which normally displayed on the mobile top screen near to the signal strength icon. I want to update this name as ‘Sentha’  :) Secure command (technically its called APDU) is:

A0A40000023F00A0A40000027F20A0A40000026F46A0D60000110153656e746861FFFFFFFFFFFFFFFFFFFF

Above bold text contains the name ‘Sentha’. Its been converted to octet (hex encoding). This command simply says, select file id 3F00 (Its the Master file MF), then select the 7F20 (its the GSM directory file DM), then select the 6F46 (EF_SPN file, its a transparent file.). Now update the file content with the given data.

In Next post, we’ll see how to create this remote APDU’s.

Connecting Serial port GSM Modem to Mac Lion

Currently I’m working on the SIM RFM (Remote File Management). Well its about reading and updating files on the mobile (u)sim cards via SMS. In-order to test  the sms pdu, I have to capture the entire messages via serial port GSM modem. Fun part is I’m using Mac Lion and of course it doesn’t have a serial port :) . After searching in the office I found a Keyspan USB-to-Serial converter. There it goes

1. Downloaded the following driver (http://www.tripplite.com/shared/software/Driver/Keyspan-Driver-for-Model-UPR-112G-USA-49WG-USA-28XG-USA-19HS-(MacOSX10.7.x%20Beta).zip) and installed it.

2. Connected the Serial GSM modem via usb

3. To make sure its detected, I checked the /dev/ and found following file : tty.USA19fd12P1.1

4. I used the ‘screen’ command to connect to it. >screen /dev/tty.USA19fd12P1.1 9600

I didn’t go much into the details of this command and bitrate 9600 (I remembered this value when I used the pduspy in windows machine :) )

5. To make sure its connected, > AT

and it replied OK

6. AT+CPIN=xxxx , and then modem is active.

7. AT+CMGL , to display the received sms pdu.

Then continued the sms pdu decoding and continued my coding ..