Click here to Skip to main content
Click here to Skip to main content

3G Modem Internet Dialer

, 13 Jul 2011 CPOL
Rate this:
Please Sign up or sign in to vote.
3G Modem Internet Dialer

This code was developed using VS2008 SP1.





A wireless 3G modem is a type of modem which connects to a cellular network instead of to the land line telephone system. It allows you to get broadband internet access anywhere you can get a cell-phone signal. Many cellular phones these days have 3G modems built into them.

There have been a lot of great articles that guide you how to write an internet dialer for regular modem (and most of them work for 3G modems too) but some information is missing, for example, signal strength, connection mode (GSM, GPRS, EDEG, HSDPA, etc.) and other information which is wireless modem related.


All my work and testing was on a Huawei modem, but things shouldn't change much with other modems. Before we get started, you need to successfully install the modem, and you should notice after installing the modem that it usually adds three ports: one for the modem and the other two for application interface. In my case with a Huawei modem, you should see the following in the device manger:

Under Modem
HUAWEI Mobile Connect - 3G Modem
Under Ports
HUAWEI Mobile Connect - 3G Application Interface (COM #)
HUAWEI Mobile Connect - 3G PC UI Interface (COM #)


We are only interested in two ports: the "Huawei Connect - 3G Modem" port which is the modem port where normal connecting and disconnecting commands should be invoked (RAS should do this for us), and the "HUAWEI Mobile Connect - 3G PC UI Interface" port that the modem uses for sending events like signal quality, signal mode, etc.

Code Design

I have tried to keep everything as object oriented as possible so the code can be reusable and easy to maintain, because not all manufacturers use the same set of commands. I used factory design pattern to select the correct class to load dynamically depending on the installed modem. An instance of CDummyModem is first created, then the modem model is identified and the appropriate class is constructed for that modem.


For dialing, there are two ways: either opening the "Huawei Connect - 3G Modem" port and issue a dial command, or letting RAS do the job for you. I took the easy way and used RAS to handle the dialing.

There are a lot of articles that talk about RAS functions in details, so I will not go deep in this. Also there are a lot of ready made classes that make using RAS functions easier but I thought of making my own.

To use CMyRas class, you will need to create an instance of CMyRas:


Then you have to call the Initialize function passing a pointer to CWnd that will be receiving the events from the RAS callback function.

    return FALSE;

Calling the Initialize function also retrieves a list of address book entries and their count. You can use GetEntriesCount to know the number of Address book entries and you can get entries by index by using GetEntry function.

Now you are ready to Dial using the function Dial, by passing the entry name that you want to dial, the user name, and the password.

To hang up a connection, just call HangUp.

Note: You need the modem to have the correct APN set or else the server will disconnect you.

Communicating with the Modem

Sending and reserving messages from the modem is straight forward, all you have to do is open the port for "HUAWEI Mobile Connect - 3G PC UI" and send your commands. If you open the modem port, you won't be able to use RAS for dialing.

I have added my own serial port class CSerial. All I needed is simply read/writing to the serial port. The CSerial Class has two threads; one for reading and one for writing. To use the class, make an instance of the class and call Initialize, which takes a pointer of CModem class to forward the received data from the port. Now you will need to open the port by calling Open function, Open function will also start reading and writing threads.

When you're done, call ShutDown to close the port and to end the threads.

Modem Events

Modem Traffic Status

Usually HUAWEI 3G modems, send their status to the "HUAWEI Mobile Connect - 3G PC UI". The DSFLOWRPT message informs us about connection status every two seconds. The received text on the serial port looks something like this:


This is an explanation for what the numbers represent:

^DSFLOWRPT: N1, N2, N3, N4, N5, N6, N7 
        N1: Connection duration in seconds 
        N2: measured upload speed 
        N3: measured download speed 
        N4: number of sent data 
        N5: number of received data  
        N6: connection, supported by the maximum upload speed
        N7: connection, supported by a maximum download speed 

Using the information that is supplied from the DSFLOWRPT event, you can draw a graph showing your connection status (upload/download over time).

Note: This event is only sent when you are connected.

Signal Quality

Once there has been a signal level change, your modem will send a RSSI event. The RSSI event shows the current signal quality level. Usually it is between 0 to 31.

This table maps the RSSI value with the signal Quality:

Wording Blocks Percentages RSSI Decibels
Excellent [][][][][] 100 31 >-51
97 30 -53
94 29 -55
90 28 -57
87 27 -59
84 26 -61
Good [][][][] 81 25 -63
77 24 -65
74 23 -67
71 22 -69
68 21 -71
65 20 -73
Fair [][][] 61 19 -75
58 18 -77
55 17 -79
52 16 -81
48 15 -83
45 14 -85
Poor [][] 42 13 -87
39 12 -89
35 11 -91
32 10 -93
29 9 -95
26 8 -97
Very Poor [] 23 7 -99
19 6 -101
16 5 -103
13 4 -105
10 3 -107
6 2 -109
No Signal 3 1 -111
0 0 <-113

Some modems don’t send status events or signal quality events, the workaround would be creating a thread that would periodically query the modem for its status.

List of Common 3G Commands

Some commands can be used for querying or setting. To Query, you will need to append a “?”. To set, you will need to append a “=”. For example, to query for a modem for current APN, use the following command:


To set the APN:

AT+CGDCONT=1,”IP”,”apn name”
AT Command Description
AT Get the modem's attention
ATI Get manufacturer information
AT+CGMI Get manufacturer information
AT+CGSN Get modem IMEI
AT^HWVER Get hardware version
AT^SYSINFO Get System information
AT+CSQ Get signal strength
AT+CGMR Print firmware version of the modem
ATZ Reset the modem back to default factory settings
AT+CFUN Get/Set operating mode
AT^SYSCFG Get/Set System configuration
AT+CUSD Sending USSD Commands

Points of Interest

What really made me do this application is that I noticed that the application that comes with the modem doesn't give accurate signal quality. There have also been options that the modem supports and there is no way to set them from the application (e.g. force connecting to 3G mode).

Also, I didn't like the modem's application GUI. All I needed is a simple clean dialer.


A good reference for AT commands and general information about 3G modems:


  • V0.6 (11 July 2011)
    • New GUI (Special thanks to Zaki Fachromi and Calvin Lichty)
    • Better Huawei (Vodafone branded) modem detection
  • V0.5 (15 Dec 2010)
    • Added Traffic graph
    • Updated context menu
    • Dialing (Bug fix)
    • Bug fixes
  • V0.4 (5 Dec 2010)
    • Now supports HUAWEI EC169 (special thanks to goldboar)
    • Basic ZTE modems support (Beta)
    • Added a thread “StatisticsThread” that can be used if the modems don’t send status events
    • Bug fixes
  • V0.3 (21 Nov 2010)
    • Added context menu to tray icon
    • Added traffic size viewer "history"
    • Set band (Bug fix)
    • Improved modem detection
    • Logger is now enabled in release build
    • A very detailed log for tracing (in debug build only)
    • License change
  • V0.2 (11 Nov 2010)
    • Added logging feature
    • Added band Selection
    • Set APN (Bug fix)
    • Added Setup Project
  • V0.1b (30 Oct 2010)
    • Added minimize to tray
  • V0.1 (22 Oct 2010)
    • Initial release

Work in Progress

  • Adding Hotspot (Wi-Fi) feature (share your 3G connection using your wireless card)


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Amro Ibrahim
Software Developer
United States United States
I love coding with C++. I always split my free time between coding and gaming Smile | :)

Comments and Discussions

AnswerRe: Happening "An incorrect structure size was detected." when invoke RasDial function in Windows XP SP2 PinmemberAmro Ibrahim3-Dec-12 5:00 
GeneralRe: Happening "An incorrect structure size was detected." when invoke RasDial function in Windows XP SP2 [modified] Pinmemberdolpari7015-Dec-12 16:58 
QuestionNo Modem Found!!! I use e137u-1 Pinmembertranduonghoan8-Nov-12 22:47 
AnswerRe: No Modem Found!!! I use e137u-1 PinmemberAmro Ibrahim3-Dec-12 4:58 
QuestionHow can i set baud rate when i create rasdial entry? Pinmemberdolpari7014-Nov-12 7:06 
AnswerRe: How can i set baud rate when i create rasdial entry? PinmemberAmro Ibrahim4-Nov-12 13:43 
GeneralRe: How can i set baud rate when i create rasdial entry? Pinmemberdolpari7014-Nov-12 15:08 
GeneralRe: How can i set baud rate when i create rasdial entry? Pinmemberdolpari7019-Nov-12 17:55 
GeneralRe: How can i set baud rate when i create rasdial entry? Pinmemberdolpari7015-Dec-12 17:11 
QuestionToolTipTitle Pinmemberkryder2-Nov-12 16:06 
AnswerRe: ToolTipTitle PinmemberAmro Ibrahim4-Nov-12 13:31 
QuestionCan i use your code in windows 7 64bit? Pinmemberdolpari70129-Oct-12 20:17 
AnswerRe: Can i use your code in windows 7 64bit? PinmemberAmro Ibrahim30-Oct-12 1:49 
GeneralRe: Can i use your code in windows 7 64bit? Pinmemberdolpari70130-Oct-12 23:49 
Thanks for your reply.
I want to use your code as dll for using in java, because i can not find any free solutions yet dealing with using internet over dial up connection (create, connect, etc)
Can't i use this code in java? (i think JNI use native c, but your code is made in C++)
if it is possible, how to create dll from your code for using in java?
I use Simcom gsm modem.
Sorry for my bad English.
GeneralMy vote of 5 PinmemberMichael Haephrati20-Sep-12 2:39 
GeneralRe: My vote of 5 PinmemberAmro Ibrahim3-Oct-12 14:34 
QuestionHow can i connect AT&T based chip modem PinmemberVyas Darshan14-Sep-12 22:59 
AnswerRe: How can i connect AT&T based chip modem PinmemberAmro Ibrahim18-Sep-12 5:28 
GeneralRe: How can i connect AT&T based chip modem PinmemberVyas Darshan3-Oct-12 0:53 
GeneralRe: How can i connect AT&T based chip modem PinmemberVyas Darshan30-Nov-12 19:48 
GeneralRe: How can i connect AT&T based chip modem PinmemberAmro Ibrahim3-Dec-12 5:03 
GeneralRe: How can i connect AT&T based chip modem PinmemberVyas Darshan4-Dec-12 0:00 
GeneralMy vote of 5 PinmemberVyas Darshan14-Sep-12 22:29 
QuestionPort Not Fount ????? [modified] Pinmemberoneclicklogin.net14-Sep-12 21:42 
AnswerRe: Port Not Fount ????? PinmemberAmro Ibrahim18-Sep-12 5:29 
QuestionProgrmatically Creating New Modem PinmemberRangaraman12-Jul-12 4:39 
QuestionAny idea how to handle voice connections? PinmemberMember 886347622-Apr-12 13:20 
AnswerRe: Any idea how to handle voice connections? PinmemberAmro Fawzy23-Apr-12 5:32 
QuestionMore information plz PinmemberSayedAbdElkrim21-Mar-12 14:26 
AnswerRe: More information plz PinmemberAmro Fawzy21-Mar-12 16:58 
GeneralRe: More information plz PinmemberMember 871352613-Apr-12 0:28 
QuestionCreating DLL PinmemberMuchamad Iman20-Mar-12 22:58 
AnswerRe: Creating DLL PinmemberAmro Fawzy21-Mar-12 16:55 
GeneralRe: Creating DLL PinmemberMuchamad Iman26-Mar-12 3:45 
QuestionHelp Needed PinmemberMember 87135268-Mar-12 23:21 
AnswerRe: Help Needed PinmemberAmro Fawzy11-Mar-12 16:11 
GeneralRe: Help Needed PinmemberMember 871352611-Mar-12 21:46 
GeneralRe: Help Needed PinmemberMember 871352612-Mar-12 0:28 
GeneralRe: Help Needed PinmemberAmro Fawzy12-Mar-12 5:04 
GeneralRe: Help Needed PinmemberMember 871352612-Mar-12 6:01 
GeneralRe: Help Needed PinmemberMember 871352612-Mar-12 23:20 
Question3G Modem Internet Dialer PinmemberT01A7-Mar-12 11:21 
AnswerRe: 3G Modem Internet Dialer PinmemberAmro Fawzy11-Mar-12 16:00 
GeneralMy vote of 5 PinmemberClaudiobsb1-Mar-12 10:03 
BugUnable to access serial port - ZTE CDMA Pinmembertestnishad28-Feb-12 21:48 
GeneralRe: Unable to access serial port - ZTE CDMA [modified] PinmemberAmro Fawzy29-Feb-12 3:07 
Questionhow to use 3g modem internet dialer for huawei usb modem device E1750c and E173Bu-1 Pinmemberonederfulkid1-Nov-11 0:11 
AnswerRe: how to use 3g modem internet dialer for huawei usb modem device E1750c and E173Bu-1 PinmemberAmro Fawzy1-Nov-11 2:16 
SuggestionPlease Update For Option Icon 461 Pinmemberbu9traq24-Oct-11 11:36 
GeneralRe: Please Update For Option Icon 461 PinmemberAmro Fawzy25-Oct-11 0:01 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.150327.1 | Last Updated 13 Jul 2011
Article Copyright 2010 by Amro Ibrahim
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid