'How automatically set an APN depending on network provider?
When a new SIM (never used) is inserted in a new smartphone (never used), smartphone seems to set a right APN without any manual settings. Is there a global table (inside smartphone) with associations APN <-> network operator?
Note: Querying new SIM cards with AT commands seems they have preferred network operators, but no APN saved in memory.
Solution 1:[1]
I can comment on the SIM side and confirm that APN settings are not held within the SIM. And yes in terms of network operators there is a file called EF_PLMN which holds the Mobile Country Code (MCC) and Mobile Network Code (MNC) to allow a device to connect to the correct network faster.
On the point of APN, it is my understanding that devices have internal (memory) APN listings for major operators in that territory. When an operator orders a device they ensure that "their" APN is correct. Yes a big issue is incorrect APNs for operators within the device and that is the reason network operators need to send APN settings when they detect a SIM in a new Device.
I do not have information on how to query this internal APN listing as it may be part of the Firmware.
Solution 2:[2]
Having been through the approval's procedure for a big USA mobile network operator (MNO), part of the approval's process involved automatically selecting the correct default APN when the modem connects to the network. This can be overridden for special cases, for example if the user needs to use an MNO supplied VPN which requires a special APN.
While I do not know if this is the same for every case, all phones go through an approval process, and if it is a phone approved by the MNO then it is quite likely the MNO will insist that at least a default APN is loaded if none has been supplied by the user. The network that the SIM allows the phone to connect to can be read from the modem without an APN being supplied, so it is quite easy to use this to look up a default APN from list. As phone companies really do not want to change their software for each MNO, maintaining a list makes it easier for the phone manufacturer, the MNO and the end user.
Solution 3:[3]
For Android, the mobile devices pull the The MCC (Mobile Country One) and the MNC (Mobile Network code) from the SIM card, and maybe other values.
Then, it configures the APN based on an internal SQlite database created by Android based on XML files that contain APN settings in the following format:
<apn carrier="CarrierXYZ"
mcc="123"
mnc="123"
apn="carrierxyz"
type="default,supl,mms,ims,cbs"
mmsc="http://mms.carrierxyz.com"
mmsproxy="0.0.0.0"
mmsport="80"
bearer_bitmask="4|5|6|7|8|12"
/>
https://android.googlesource.com/device/sample/+/master/etc/apns-full-conf.xml https://source.android.com/devices/tech/config/update
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | QuickPrototype |
| Solution 2 | andrew g |
| Solution 3 | user14219984 |
