Re: Stop this APN madness!



On Fri, 2008-08-22 at 13:46 +0300, Antti Kaijanmäki wrote:
> Hi,
> 
> hopefully didn't get caught in spam filters, just wanted to add a little
> drama. This is serious! :P
> 
> Let's talk about APNs and GSM modems a bit. Currently we have
> nm-connection-editor page for mobile-broadband devices. On mobile
> broadband settings tab you can set the number to dial to and the APN.
> Now, I think this is something that should be changed.
> 
> DISCLAIMER:
> I might be wrong on something as this all is based on my personal
> experience. I also have a copy of an AT command reference guide[1].
> 
> 
> 
> First of all let's see how this dial number works. 
> Quite often you hear thing like "just dial 'ATD*99#' and you should be
> ready to go"[2]. Well this works for someone, but might not work for
> somebody else. The reason for this is that the specification[1] says
> (page 51) ATD command is given in form:
> 
>     atd*<gprs_sc>[*<addr>][*[<L2P>][*[<cid>]]]]#
> 
> where gprs_sc is 99.
> 
> In my experience *99# is just a shorthand command meaning *99***1#,
> although it's not said in the specification that <cid> defaults to 1.
> Anyway now you see the magical CID that I talked some months back.
> 
> CID means PDP Context Identifier (page 151) and as we can see the
> dialing command must always specify a CID what to use to establish the
> connection. And thus *99# works automatically if CID 1 happens to
> contain correct settings. 
> 
> 
> If you issue your modem a command "AT+CGDCONT?" you can get a list of
> available PDP contexts.
> 
> Here's a nice example of Sony Ericsson K750:
> AT+CGDCONT?
> +CGDCONT: 1,"IP","wap.omnitel.it","0.0.0.0",0,0
> +CGDCONT: 2,"IP","mms.tim.it","0.0.0.0",0,0
> +CGDCONT: 3,"IP","wap.omnitel.it","0.0.0.0",0,0
> 
> this is also from Sony Ericsson K750i:
> AT+CGDCONT?
> +CGDCONT: 1,"IP","internet.telenor.se","0.0.0.0",0,0
> +CGDCONT: 2,"IP","internet.telenor.se","0.0.0.0",0,0
> +CGDCONT: 4,"IP","internet.telenor.se","0.0.0.0",0,0
> +CGDCONT: 5,"IP","internet.telenor.se","0.0.0.0",0,0
> 
> and here's one from Nokia N81:
> AT+CGDCONT?
> +CGDCONT: 1,"IP",,,0,0
> 
> and this is from a brand new Huawei E169 that's first time plugged in:
> at+cgdcont?
> +CGDCONT: 1,"IP","","0.0.0.0",0,0
> 
> 
> For those who don't know, APN is the string after "IP".
> 
> 
> And here's an example how the Huawei behaves when I specified CID 2:
> at+cgdcont=2,"IP","foobaar"
> OK
> Aat+cgdcont?
> +CGDCONT: 1,"IP","","0.0.0.0",0,0
> +CGDCONT: 2,"IP","foobaar","0.0.0.0",0,0
> 
> and note, this is after I unplugged and plugged the thing back in:
> at+cgdcont?
> +CGDCONT: 1,"IP","","0.0.0.0",0,0
> +CGDCONT: 2,"IP","foobaar","0.0.0.0",0,0
> 
> As you can see some devices retain their setting even after a power loss
> or reboot. And some do not, Like Nokias. And the situation does not
> improve by the fact that some mobile phones (I've heard, not witnessed)
> use the PDP Contexts also for internal browser or WAP or whatever so if
> those are altered by NM there's a change that we could break some
> functionality of the mobile phone.
> 
> So it's not safe to blindly override CID 1 or anything else for that
> matter.

Probably not.  As an enhancement, NM should:

1) Issue AT+CGDCONT=? to get the allowable range of CID slots; not all
devices conform to the standard here of course so you have to quirk
stuff.  Some phones may have fewer than 10 slots.  Some devices may have
all slots filled.

2) Iterate over all the slots with AT+CGDCONT? and search for the
user-specified APN.

3) If the user-specified APN is found, use that slot.

4) If the user-specified APN is not found, use a free slot.

3) If there are no free slots, use the last slot and overwrite whatever
is there.

> Now let's talk about APNs, shall we. Once again you hear a lot of "just
> use 'internet' as APN and you should be ready to go". Well that might be
> true for some providers, but just for example take a look provider
> information of India[3].

That's where MBCA comes into play, to gently ask the user which APN they
need :)

> On most cases if you use wrong APN you just don't get connected. No true
> harm there except frustrated users. But now a more disturbing scenario;
> some service providers have multiple billing methods for mobile
> broadband. There's at least constant monthly fees, pay-per-Mb and even
> pay-per-time. The selection between these is done by selecting a
> specific APN. 
> 
> Just think for a minute here if we just blindly issue *99* and that's a
> pay-per-Mb APN (CID 1) when the user thinks he has constant monthly fee
> (CID 2). Or "internet" is the pay-per-Mb APN of users service provider.
> Or we break the users phone by overriding CID 1 with something.

I think if you don't enter an APN, it'll just use the default APN which
should have been set up from your provider as such.  Of course that
might be the wrong APN, but at some point the user needs to take
responsbility for knowing how to operate their equipment.

> Okay. Enough hot air. Now some concrete solutions.
> 
> on nm-connection-editor:
>  * remove the dial number entry and move the APN entry to it's place

Probably; I'm not aware of any mobile broadband providers that don't use
the standard numbers, so we can hide this for now.

>  * under the hood set gsm.number to ### (see below for explanation)

Well, we'd just make it NULL/blank actually, that means "not present".

> NM (or modem-manager):
>  * when mobile broadband connection is activated check the dial number
>  * if the number is not ###, just dial the damn thing
>    - don't set APN or anything. User clearly knows which CID is correct.

You can find wrong directions all over the web.  What I'd prefer to do
is require an APN, and if the APN is not present, dial the default APN.
In conjunction with that, make it really easy to select the APN via the
assistant and require this on creation of the connection.  Perhaps don't
immediately connect GSM-based devices from the applet, but bring up the
mobile broadband wizard and select an APN for the connection first.

>  * if the number is ### do something smart
>    - first check if specified APN is already assigned to some CID 
>      - get the list using "AT+CGDCONT?" and iterate that
>      - if found, use that CID for dialing (ATD*99***<cid>#)

Yes.

>    - if the APN is not set then try to append it to the list
>      - AT+CGDCONT=<cids+1>,"IP",<apn>

Yup, but subject to the maximum number of CIDs available which has to be
queried too.

>      - check that it really was appended to the list and use it
>    - if appending fails for some reason just override CID 1
>      - AT+CGDCONT=1,"IP",<apn>
>      - good fail safe would be storing the original CID to a file so
> that it can be manually restored if we manage to break someones phone.

Maybe, but that's icing on the cake after doing the rest of the stuff.
I'm a big fan of not coding something until you actually find out it's
needed.

Dan



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]