Code Repo    |     RSS
MD's Technical Sharing



Thursday, December 17, 2009

Using USSD on Windows Mobile to set call forwarding

In one of my recent projects, I need to set the call forwarding programmatically. My first attempt was to use the RIL_AddCallForwarding and RIL_GetCallForwardingSettings APIs provided by RIL. However, on all phones I tested, these API mysteriously failed with either E_FAIL, E_NOTIMPLEMENTED or E_INVALIDARG. After a few attempts, I gave up and concluded that these APIs are supported only on Windows CE, but not Windows Mobile (or at least MSDN says so).

My next attempt  is to send USSD via lineSendUSSD() method. For example, to divert all incoming calls to another number, use **21*«dest number»#. Since the USSD codes to set call forwarding status are fixed, this methos should work for all phones (see this for the exact USSD codes). However, after some testing, this method is not as reliable as it sounds. It works perfectly on some phones. On some others  the call to lineSendUSSD() returns E_FAIL when I passed in the code to set call forwarding but the same API works fine for 'normal' USSD code (e.g. *100# to check account info). On other phones, I received a response from the mobile operator saying that the service code is invalid - it seems as if the phone literally sends the USSD string to the mobile operator, instead of processing it and gives me the call forwarding status.

On a side note, using the .NET method Phone.Talk() on any USSD string will simply display an error message, saying that the signal is unavailable. Also, lineSendUSSD() are not supported on all phones. On phones where it is supported, not all USSD codes are accepted and the response cannot always be retrieved easily. It will most likely fail if the mobile operator returns a menu response for your USSD code (e.g. Reply with '1' for account balance, '2' for expiry date), in which case I haven't figured out how to reply programmatically, or even to retrieve the response text. It looks as if it has to do with the registry branch HKEY_LOCAL_MACHINE\Services\USSD\.

At the moment, I have no ideas why Microsoft makes it so difficult for developers just to send a USSD code.

7 comments:

  1. hi,

    I am also working on similar kind of application for which i need call forwarding and i have used lineSendUSSD() & lineGetUSSD methods which are not working for call forwarding but it works nicely for other USSD commands.

    So, did you get ant success over this.

    It will be very much helpful to me, if you give me some idea over this.

    Waiting for your reply

    ReplyDelete
  2. Hi

    So far I am only successful in using lineSendUSSD and lineGetUSSD method to set call forwarding or get its status on HTC phones. On all my HTC phones (HTC Touch, HTC Touch 3G, HTC Touch HD2), these methods seem to work well. On other phones I tried, the methods fail.

    As mentioned in the article, you can try the RIL_AddCallForwarding and RIL_GetCallForwardingSettings API. If the firmware supports these APIs, they will work.

    ReplyDelete
  3. My code also works well with other USSD Commands like balance enquiry etc but not for Call Forwarding.

    So,if you don't mind then will you share your code with me.

    It will be highly helpful to me.

    Thanks in advance.

    ReplyDelete
  4. Hi, I have some VB.NET code to P/Invoke RIL_AddCallForwarding and RIL_GetCallForwardingSettings. The code is not fully tested, but I can send it to you if you want.

    Also can you explan how lineSendUSSD does not work for Call Forwarding commands, but works for others e.g. balance enquiry? Is the behaviour mentioned in the article?

    ReplyDelete
  5. Hi
    Can you help me.
    I like to send ussd command (balance request) with C#
    Thanks
    -----
    salem.bouzidi(at)gmail.com

    ReplyDelete
  6. Here is probably why for balance query is working but not for call forwarding. I hope it helps you.
    - For the account balance (*100#), USSD operation is used. That is, the USSD string is sent to the network which will analyse the string and do what it is configured (query balance in this case). This USSD string is configured in the network side.
    - For **21*Dest No# - this string should be interpreted by the phone, and the phone should send a MAP_Register_SS_req message to the network (HLR) to register the CFU. This string is not configured in the network, but in the phone.
    All above is according to 3GPP and other related standards.
    So, if you use lineSendUSSD, then the **21*DestNo# string is send to the network, but in the network side there is no configuration for this string. It should be interpreted by the phone and the phone should send a MAP_Register_SS_Req message to the network as explained above

    ReplyDelete
  7. Thanks so much for the useful info :)

    ReplyDelete

Note: Only a member of this blog may post a comment.