Thursday, January 19, 2017

Notes on GSM USB dongles on linux.

Analyzing Huawei GSM dongles


In the last few months I've been writing drivers for Huawei GSM dongles. In particular to be used in combination with the Android RIL (Radio Interface Layer). In general Android runs on top of a Linux Kernel. The drivers that ships with GSM dongles typically works with Windows software. So we often have to do some reverse engineering. 

Here are my notes:

My target environment is a Linux Kernel 2.6....  My first step is to see if it works with the Windows software. Does the dongle pick up a signal. Can it register to a network. etc. 
Next step, setup a connection by providing the relevant APN, username and password. 

Huawei dongles typically ships with variations of Mobinil software. There is an option to use different connection type. RAS (modem) or NDIS

Selecting RAS (modem) mode
When you select the RAS (modem) we can use a tool like USBlyzer to inspect the AT commands that are used to register the the GSM dongle to the network.

There are generic AT commands but  also vendor specific AT commands.

... to be continued.







Linux 

When switching to Linux the first challenge you might run into is that the device nodes are not created. Typically their modem software is included inside the GSM dongle and will be installed by telling the OS that it is a mass storage device, or tells the OS is behaves as a CD-rom. And it launches the install software.

In order to stop fooling the OS, we can use a tool USBMode_switch. The site has good forum discussions and a lot of hints to get your specific vendor dongle recognized. Most linux distros have a very recent version installed. What you might notice is that the product id from the GSM dongle is changing. 
You can see this when you call 'lsusb' and do this a couple of times (every 5 sec) while putting in the GSM dongle. 
You will see the USB being recognized by linux. It disappears briefly and reappears with a different product id.  You can see with 'dmesg' that new device nodes are being created. If that is not the case you first have to go over this hump. 


AT commands 

AT+CLAC will reveal most (not all) supported commands for the stick
There are different options to send the commands and monitory the result.

I've used putty on linux and start a serial connection type. (the /dev/ttyUSB3 is just an example.)

A bit more primitive but still working is to open to shell sessions.
Monitor the output in one session:

cat /dev/ttyUSB1

And in another terminal session, send the at commands.:

echo "AT^SETPORT=?" > /dev/ttyUSB1

The question is to find out which node you can use. And I've only come to a trial and error mode.
I quickly try the commands
cat /dev/ttyUSB1
cat /dev/ttyUSB2
cat /dev/ttyUSB3
cat /dev/ttyUSB4
...
To find out on which node I can communication. You will often see some AT^BOOT messages, ^RSSI, ^CSNR, ^MODE messages  passing by. They are rather an annoyance when you use putty. So the first commands I use during a putty session is to

  • turn off the boot messages with  AT^BOOT=0,0
  • turn off RSSI reporting with AT^CURC=0


The output of the AT^SETPORT=?" will give you a list of the different 'ports'.

output::
1:MODEM
2:PCUI
3:DIAG
4:PCSC
5:GPS
6:GPS CONTROL
7:NDIS
A:BLUE TOOTH
B:FINGER PRINT
D:MMS
E:PC VOICE
A1:CDROM
A2:SD

You can enable /disable these 'ports' by enumerating them in the AT^SETPORT="A1,A2;1,2"
This would enable modem and pcui on ttyUSB0 and ttyUSB1.

If you change the order AT^SETPORT="A1,A2;2,1"
The modem and pcui will be on ttyUSB1 and ttyUSB0.

I'm not sure how to reset a dongle to factory setting to restore the port mode. But you can imagine, you have to be carefull with these AT commands. If you disable the Application interface (PCUI) I would not know of a mechanism to undo you changes (maybe via the NDIS interface?)


echo -e "AT^GETPORTMODE" > /dev/ttyUSB1

output:: /
^getportmode:type:WCDMA:Qualcomm,MDM:0,NDIS:1,DIAG:2,PCUI:3

(suggesting it was 1,7,3,2)


# echo -e "AT^SETPORT=\"A1,A2;1,2\"" > /dev/ttyUSB1


plug in and out the dongle.
ls /dev/ttyU*
/dev/ttyUSB0  /dev/ttyUSB1

# echo "AT^GETPORTMODE" > /dev/ttyUSB1

^getportmode:type:WCDMA:Qualcomm,MDM:0,PCUI:1


E353 specific


TIGO dongle:


echo "AT^SYSCFG=?" > /dev/ttyUSB1
^SYSCFG:(2,13,14,16),(0-3),((400380,"GSM900/GSM1800/WCDMA2100"),(4a80000,"GSM850/GSM1900/WCDMA850/WCDMA1900"),(3fffffff,"All Bands")),(0-2),(0-4)

Probably default is 
echo -e "AT^SETPORT=\"A1,A2;1,7,3,2,A1\"" > /dev/ttyUSB1



3 Dongle:

echo "AT^GETPORTMODE" > /dev/ttyUSB4

^getportmode:type:WCDMA:Qualcomm,MDM:0,NDIS:1,DIAG:2,PCUI:3,CDROM:

"AT^SYSCFG=?" > /dev/ttyUSB4
^SYSCFG:(2,13,14,16),(0-3),((400000,"WCDMA2100")),(0-2),(0-4)



Thursday, November 10, 2011

Watin => Selenium ?

I've been using Watin for quite some browser automation projects. But it seems that Watin is a bit dead in the water. No Chrome support. No Firefox 4 or higher support. It also seems to be an heroic effort of a few people.

So it might be time to move over to Selenium. Active development, wide browser support...

Sunday, September 26, 2010

Friday, April 25, 2008

External function calls

The latest release of the Rule Manager allows to import external functions into the business vocabulary. As a little exercise I tried to get the current weather condition for a zipcode (maybe I can write some rules if I should bring my umbrella while I leave my house in L.A.)

Initially I intended to call a webservice, but it seems that all free weather webservice calls is something from the past. Yahoo offers weather information as an RSS feed. So a simple XPath query can select the information that I'm interested in:

Here is the code (note the FunctionAttribute decoration on the method)


1 using System.IO;

2 using System.Net;

3 using System.Xml;

4 using AcumenBusiness.IModel;

5 using Type=AcumenBusiness.IModel.Type;

6

7 namespace TestCallWebService

8 {

9 [Concept("Weather info", "Try to get weather forecast from different services")]

10 public class WeatherInfoProvider

11 {

12 private static readonly string YahooWeatherURLFormat = "http://weather.yahooapis.com/forecastrss?p={0}";

13

14 [Term("workaround", "import function requires one field. (bug)")]

15 private string dummyField;

16 public string DummyField

17 {

18 get { return dummyField; }

19 set { dummyField = value; }

20 }

21

22 [Function("Get temperature", "Get the weather info from Yahoo",

23 ReturnType = Type.text,

24 ArgumentTypes = new Type[] { Type.integer })]

25 public static string GetWeatherInfoAsFeed(int zipCode)

26 {

27 HttpWebRequest request = (HttpWebRequest) WebRequest.Create(string.Format(YahooWeatherURLFormat, zipCode));

28 // execute the request

29 HttpWebResponse response = (HttpWebResponse) request.GetResponse();

30

31 // we will read data via the response stream

32 Stream resStream = response.GetResponseStream();

33 XmlDocument rssFeed = new XmlDocument();

34 rssFeed.Load(resStream);

35

36 //set an XmlNamespaceManager since we have to make explicit namespace searches

37 XmlNamespaceManager xmlnsManager = new System.Xml.XmlNamespaceManager(rssFeed.NameTable);

38 //Add the namespaces used in the xml doc to the XmlNamespaceManager.

39 xmlnsManager.AddNamespace("yweather", "http://xml.weather.yahoo.com/ns/rss/1.0");

40

41 XmlNode weatherCondition = rssFeed.SelectSingleNode("/rss/channel/item/yweather:condition/@temp", xmlnsManager);

42 if (weatherCondition != null) {

43 return weatherCondition.Value;

44 }

45 return null;

46 }

47 }

48 }



With the Import Schema adapter I can import this function and call it from my business rules. The coolest part is that you can invoke this from the Interactive Rule Map. So you can see how your rules are executing with this external data. It seems to be 76 fahrenheid in L.A.
Nice weather to jump on the bike and cycle to work...





Thursday, January 10, 2008

.NET SOA BizTalk: BizTalk Tools and guidelines

Kishore Dharanikota has created a nice list of tools and guidelines for BizTalk developers and designers .NET SOA BizTalk: BizTalk Tools and guidelines. The Rule Manager is mentioned in the Development category. Interesting to see this classification. I probably would have placed it in the Design category. But that all depends on your frame of reference. Or it might hint that many BizTalk developers are playing a dual role of business analyst and developer.

Tuesday, October 30, 2007

RenewCert - Renew Expired Certificates

It's been just over a year when I deployed the RuleManager with a ClickOnce certificate. Today it expired. Visual Studio 2005 would suggest to generate a new certificate file, however none of the existing users would be able to update the Application (because of different certificate keys).
The error you would get is:

System.NullReferenceException: Object reference not set to an instance of an object.
at System.Deployment.Application.ApplicationTrust.RequestTrust(SubscriptionState subState, Boolean isShellVisible, Boolean isUpdate, ActivationContext actCtx, TrustManagerContext tmc)
at System.Deployment.Application.DeploymentManager.DetermineTrustCore(Boolean blocking, TrustParams tp)
at System.Deployment.Application.DeploymentManager.DetermineTrust(TrustParams trustParams)
at System.Deployment.Application.ApplicationDeployment.CheckForDetailedUpdate()



There is a workaround made by Cliff Stanford RenewCert, which allows you to regenerate an expired certification.

Thanks Cliff!

Sunday, October 14, 2007

Graphical Rule Editor for RuleML format


In the last few weeks we have created the RuleML adapter for the Rule Manager. The RuleML adapter allows to export a business rules policy to the Reaction RuleML format.

Please bear with us that we are no experts in RuleML and certain rule constructions might be exported incorrectly. I hope the RuleML community can provide us with the feedback and we will incorporate any changes into our automatic update process as soon as possible. You can give feedback at the http://www.acumenbusiness.com/support forum.

Installation:
The Rule Manager product is available from the website http://www.acumenbusiness.com/

You can export to the RuleML format by installing the RuleML adapter module. See the screenshot [Menu: File\Options\Adapters\Rule ML]

The adapter will provide the new export format "RuleML (*.rrml)" in the Export wizard. [Menu: File\Export]
You can set .rrml as the default export type by changing the File Export type on the Import & Export options
[Menu: File\Options\Import & Export\File Export = RuleML (*.rrml)]

An example of the Driver Eligibility export is here
Posted by Picasa