0

I have a Ncell (Nepali cellphone company) SIM card that I want to use in the built-in 3G modem ("Gobi 2000" hardware) in my Ubuntu-based notebook.

The card uses Ncell's "normal" tariff, not Ncell Connect. Accordingly, I cannot book the cheap, never expiring Ncell Connect data packages, but want to use Daily Internet Packs, which seems to be the next cheapest and most flexible option.

Question: How to use any of the options to book these packs successfully under Ubuntu, with the SIM in the notebook? (e.g. the USSD menu option, or Ncell Ecare, which requires SMS confirmation)

Ideally, the solution should be automated as much as possible, and also prevent me from running into the more expensive data rates when the Daily Internet Pack's volume is exhausted.

tanius
  • 6,610
  • 2
  • 42
  • 52

2 Answers2

1

After much experimenting, the following is my best solution so far.

Solution: Use atinout to book via USSD menu

USSD is used by mobile network operators for responsive service menus – see Wikipedia on USSD. Booking via Ncell's *17123# USSD menu via the computer that has the SIM is the most comfortable option.

Since dedicated USSD client software did not work for me (see below), I use raw AT commands. For that, I will first install atinout, a small command line utility for using AT commands:

sudo apt-get install ruby-ronn;
git clone git://git.code.sf.net/p/atinout/code atinout;
cd atinout;
make;
checkinstall make install;

Then, I can use it with AT USSD commands to, for example, book a Daily Internet Pack 40 MB. Here's a full transcript. After the modem confirms your command with OK, wait a few seconds and press Enter to display the USSD answer (which should have arrived by then). Then press Ctrl+C to terminate atinout (^C in the transcript), and restart it again.

$ sudo stop modemmanager
stop: Unknown instance:

$ atinout - /dev/ttyUSB1 -
AT+CUSD=1,"*17123#",15
OK
+CUSD: 1,"1.) 1 day Pack 
3.) Facebook Pack 
4.) 7 Day Pack  
6.)  30 Day Pack 
8.) Unlimited Pack  
Note: 
Back:* Top:#",15
^C

$ atinout - /dev/ttyUSB1 -
AT+CUSD=1,"1",15
OK
+CUSD: 1,"1.Light 6 MB Rs 6 
2.Light 12 MB Rs 9 
3.Medium 18 MB Rs 12 
4.Heavy 40 MB Rs 20 
5.Deactivate 
Note: 
Back:* Top:#",15
^C

$ atinout - /dev/ttyUSB1 -
AT+CUSD=1,"4",15
OK
+CUSD: 1,"1.One time Activations 
2.Auto Renewal Activations 
Note: 
Back:* Top:#",15
^C

$ atinout - /dev/ttyUSB1 -
AT+CUSD=1,"1",15
OK
+CUSD: 0,"Dear Customer, your 40 MB pack with 24 hours validity 
is currently processing and will be activated within 10 min. ",15
^C

You can combine the above into one script (assuming for now you don't have to retry any command; the AT is just to display the USSD answer):

sudo stop modemmanager && \
atinout - /dev/ttyUSB1 - < <(echo "AT+CUSD=1,\"*17123#\",15") && sleep 4 && \
atinout - /dev/ttyUSB1 - < <(echo "AT") && \
atinout - /dev/ttyUSB1 - < <(echo "AT+CUSD=1,\"1\",15") && sleep 4 && \
atinout - /dev/ttyUSB1 - < <(echo "AT") && \
atinout - /dev/ttyUSB1 - < <(echo "AT+CUSD=1,\"4\",15") && sleep 4 && \
atinout - /dev/ttyUSB1 - < <(echo "AT") && \
atinout - /dev/ttyUSB1 - < <(echo "AT+CUSD=1,\"1\",15") && sleep 4 && \
atinout - /dev/ttyUSB1 - < <(echo "AT");

(Note, this script uses a technique to avoid pipe characters.)

Troubleshooting

Multiple AT+CUSD commands in a row. For some reason, with my 3G modem (Gobi 2000), in 90% of cases, only one AT+CUSD can be executed successfully, then atinout has to be restarted. To prevent difficulties, in the process above we restart atinout simply every time in the transcript above. This does not end the USSD session (an "open" USSD menu).

If the modem does not answer with OK. When going along the above transcript, take care that every command is confirmed with "OK" by the modem. If not, restart atinout and try again. If that does not help, start the whole process again. And if that does not help, your modem might be in a strange state. Reset it, or just let the computer go through a suspend / resume cycle.

Using AT commands in general. For more details about communicating with a modem using AT commands under Linux, see this answer.

When booking a Daily Internet Pack fails. The Ncell Ecare website would fail without an error message and show the list of services again, instead of a success message of a form to enter a SMS confirmation code. This condition happens if you still have an active monthly (or also weekly?) Internet pack. Even if no data balance is left of it. You can check that and if necessary cancel the pack here. However for me, even after cancelling the pack, a data balance query by SMS would return "Dear Customer, You have […] MB data left in your Monthly account which will expire […]." and it was still impossible to book a Daily Internet Pack. I would have to wait until the expiration date. Maybe try putting the SIM into a phone and book the first Daily Internet Pack via USSD code (dial *17123# and follow the on-screen menu.)

Future Improvements

Automation. With the above solution, we have to navigate the menu manually, and try again if something goes wrong. Could be better.

Automatic re-booking. Ideally, this solution would include automatic (re-)booking when the data balance runs low. This can be detected by the Ncell warning SMS and / or traffic monitoring. This would not book a new pack automatically when it expires naturally, but then notify the user with a status icon that she's browsing with the expensive rate.

Be notified when the data balance runs out. If so, we would not require transferring limited amounts to the SIM card, but could transfer a large amount and would be warned (for example by a big red icon in the task bar) when running into the expensive rate. There are at least two ways for this:

Getting the Ncell notification SMS during an active data connection. Ncell sends it when the data balance runs low. See the point above on wvdial etc. how this could work. It does not work with NetworkManager and gammu out of the box, since it grabs both modem control channels.

Limiting data traffic. NTM would be a candidate tool for this, but it currently does not have a feature to set one-time pack data limits with exact start time.

Alternative USSD client software (not working for me)

There are dedicated USSD clients under Ubuntu Linux, but they did not work for me for various reasons (my 3G modem hardware: Gobi 2000). However, with some debugging, you might get them to work. The usage of some is treated in more detail in this question and this question.

The list, with the most promising candidates first:

  • mmcli. ModemManager and its command line client mmcli seem to be great software and the best bet for this task. See this answer on StackOverflow for how to use mmcli to navigate USSD menus. However, after solving a problem with always-on PIN2 lock on Ncell SIM cards (solution similar to this), mmcli would still refuse sending USSD commands via the Gobi 2000 3G modem, due to a bug (because the modem uses USSD with other clients software successfully):

    $ sudo apt-get install libqmi-utils
    $ sudo qmicli -d /dev/cdc-wdm0 --dms-uim-verify-pin=PIN2,0000
    $ sudo qmicli -d /dev/cdc-wdm0 --dms-uim-get-pin-status
    $ mmcli -m 0 -e  # Index as found via mmcli -L
    $ mmcli -m 0 --3gpp-ussd-initiate="*100#"
    error: Modem has nn USSD capabilities.
    
  • gsm-ussd. gsm-ussd is a command line utility exclusively for sending USSD codes, and it can operate USSD menus (see how in this answer). For Ncell though, I was able to send USSD codes and get answers, but not to operate USSD menus. There would be various inconsistent error messages, and I did not investigate if the problem is my hardware, gsm-ussd or Ncell's implementation of USSD.

  • gammu. gammu is a Linux command line utility that can send USSD codes, but according to this question, it cannot use USSD menus yet. python-gammu contains a script service_numbers.py that is meant to enable this. It did not work for me though.

  • ofono. ofono has a similar purpose and interface as ModemManager [source], just that it is made for Ubuntu Touch (which can run on mobile phones). Its main interface is DBus, but you can use its test case command line tools to send USSD commands and operate USSD menus (examples, more examples). However, it seems to need a rild (Radio Interface Layer Daemon) implementation to function, and that would only be available on actual mobile phones. When starting, ofonod would complain about not being able to connect to rild, and I could not find a rild to install on a normal Ubuntu Linux installation.

  • ussdq. ussdq is another small utility for Linux that includes a feature to operate USSD menus. However, it no longer in active development sincee 2013, and compiling it is a bit of an effort (it uses the Gambas2 framework, but recent Ubuntu Linux versions only include packages for Gambas3).

tanius
  • 6,610
  • 2
  • 42
  • 52
0

See also my other answer, which I think is the better one.

Solution: Book via Ncell Ecare website

Booking via USSD commands is the most comfortable solution (see my other answer). But if it does not work for you for some reason, here is another, less comfortable but working alternative.

  1. Transfer 25 NPR to the computer's SIM card. As many times as you want to buy Daily Internet Packs at the same time. The fastest and most comfortable way for this is to dial a corresponding USSD code *17122*<980… mobile number>*25# [source] from your address book. The price includes the 1.25 NPR charge for the transfer, and taxes added when booking the 40MB Daily Internet Pack for 20 NPR.

  2. Create a wifi hotspot with the phone. And connect the computer to it, or use an existing wifi connection if available.

  3. Book one-time "40 MB Heavy" Daily Internet Packs on Ncell Ecare. You can book multiple ones in a row, and the data volume will aggregate. You will have to confirm the first booking with a confirmation code received by SMS. Obtain that SMS for example as follows:

    1. Execute gammu deletesms 0 1 (assuming you don't need the SMS stored in slot 1) to make space for the incoming SMS. It will be received in the first free space (guaranteed 1 here), but would not be received if all 20-30 storage spaces on the SIM card are used up.

    2. Click "Send SMS" in the Ncell Ecare website's book process.

    3. Execute gammu getsms 0 1 to obtain the confirmation SMS.

    4. Enter the confirmation code on the Ncell Ecare website.

  4. Use Internet via mobile data until it stops working.

  5. Confirm that the balance has run out with a balance check. In short:

    gammu deletesms 0 1 && \
    gammu sendsms TEXT 9909 -text "status" && \
    sleep 10 && \
    gammu getsms 0 1
    

    Disconnect your mobile broadband connection if it does not work otherwise (some connection managers grab both modem control channels, leaving none for gammu).

  6. Repeat.

Troubleshooting

Simplifying login to Ncell Ecare. Using the Ncell Ecare website frequently is uncomfortable because it prevents the login data from being saved by the browser, prevents copy&paste to be used for pasting into the password field, and additionally, has a captcha on the login form. Solution:

  1. If using Firefox, install the Autofill Forms addon.

  2. Then visit the Ncell login page, right-click into a field and choose "Add complete form as profile …".

  3. In the profile creation dialogue, modify the site rule matching to be (?:ecare\.ncell\.com\.np:9443), and enter your values for username and password.

  4. Copy that profile and adapt it for other SIM cards you have.

  5. From now on, to log in, right-click anywhere on the login page except into a form field, and choose "Autofill Forms → ".

  6. (Optional) To allow pasting into the password field, install the FoxReplace Firefox addon and set up a rule for URL https://ecare.ncell.com.np:9443/nser/index.do?method=init with the "HTML for input and output" option set and the action to replace the text onkeydown="keyDownForbidCopyPaste(passwordIn) with nothing.

  7. (Optional) If you really want to To get rid of the captcha solving, solve the captcha problem, you can use the Rumola browser addon. However note that a captcha solving will cost 0.013 USD with them, since it involves (at least sometimes) human processing. Their auto-search for captchas does not work for the Ncell Ecare login form. Instead, right-click into the captcha text field and choose "Use this field to enter Captcha". Then double-click into the field to let Rumola solve the captcha. While that is in process, use the "Autoform fill" step from above to fill in the remaining login info.

Solution when the Ncell Ecare website shows a WSOD. WSOD = white screen of death. You would see just a white content area in your browser when visiting the website. This is a bug in their web application that is triggered when experiencing an Internet connection failure while logged into Ncell Ecare. To fix this condition, there are at least the following options:

  • Delete cache and cookies stored for the Ncell Ecare login, go to the login page again, and log in again.

  • Switch to a different Multifox profile (for Firefox) or MultiLogin profile (for Chrome), and reload the page.

Also see my other answer.

Possible future improvements

Using the mobile broadband connection to book the package. This will work once I find out how to receive the confirmation code SMS (for booking the data package in the Ncell Ecare website) while the data connection is active. Does not work with Linux NetworkManager and gammu out of the box, because network-manager will grab both modem control channels, leaving none for gammu. The alternative of disconnecting, getting the SMS with gammu and then reconnecting does not work either because Ncell forces a logout then, and this invalidates the SMS confirmation code as well. Somebody reported that using wvdial instead of NetworkManager to connect fixed this [source].

Get SMS automatically, in notifications. Like the steps above, it requires a way to work with SMS during an active data connection. It would show the confirmation SMS when booking an Internet Pack via the Ncell Ecare website, and move it to the hard disk to keep the SIM card storage spaces free for recceiving new SMSs. This would speed up the process compared to the current proposal with a manual command to get the confirmation SMS off the SIM card.

Booking via Ncell Ecare without SMS confirmation. Would simplify the process a lot, as one can use the computer's mobile broadband connection to book the Internet pack. Needs Ncell action.

Booking via Ncell Ecare website without forced logout. Would simplify the process a lot just like not needing SMS confirmation, as one can use the computer's mobile broadband connection, switch it off to get the SMS, then switch it on again to enter the confirmation code into Ncell Ecare. Currently this will force a logout, which invalidates the confirmation code as well.

Booking via Ncell app that allows managing external SIM cards. In this case, the Ncell app would allow managing multiple SIM cards without needing the other SIM cards physically in the phone. In principle like the Ncell Ecare website. Again, needs action by Ncell.

Also see my other answer.

Non-working alternatives

Booking with the Ncell Ecare website in a smartphone browser. Tried this, but could not log into that website with the smartphone for some reason. The login button would just do nothing. Also, since that website is not mobile friendly, booking on the computer via a wifi hotspot connection seems more comfortable anyway.

Installing the Ncell app twice. There are ways how to download and modify any Android so you can install it twice (I used this solution for the Ncell app). I hoped it would allow me to log in with two different accounts, managing my phone's and computer's SIM card in parallel. However, login in the Ncell app depends on SIM card detection, you cannot use it to manage a non-present SIM card.

Booking via Ncell app in a simulator. You can run Android and the Ncell app in a virtual machine like OpenBox, but it will be hard to fake the SIM card detection to it.

tanius
  • 6,610
  • 2
  • 42
  • 52