Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add SIM/USIM communication via modem AT commands #13

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

Nementon
Copy link

@Nementon Nementon commented Mar 2, 2024

This PR will add support for SIM/USIM communication via a modem device using the AT+CSIM command. It has been tested with a USIM:

from card.USIM import *

usim = USIM(modem_device_path="/dev/ttyUSB2")
print(f"IMSI << {usim.get_imsi()}")
print(f"get_services << {usim.get_services()}")
usim.dispose()
In [1]: %ed a.py
Editing... done. Executing edited code...
IMSI << 001010000104267  
get_services << ['2 : Fixed Dialling Numbers (FDN) : available', '3 : Extension 2 : available', '4 : Service Dialling Numbers (SDN) : available', '5 : Extension3 : available', '6 : Barred Dialling Numbers (BDN) : available', '8 : Outgoing Call Information (OCI and OCT) : available', '9 : Incoming Call Information (ICI and ICT) : available', '10 : Short Message Storage (SMS) : available', '11 : Short Message Status Reports (SMSR) : available', '12 : Short Message Service Parameters (SMSP) : available', '13 : Advice of Charge (AoC) : available', '14 : Capability Configuration Parameters 2 (CCP2) : available', '15 : Cell Broadcast Message Identifier  : available', '16 : Cell Broadcast Message Identifier Ranges  : available', '17 : Group Identifier Level 1 : available', '18 : Group Identifier Level 2 : available', '19 : Service Provider Name : available', '20 : User controlled PLMN selector with Access Technology : available', '21
 : MSISDN : available', '24 : Enhanced Multi-Level Precedence and Pre-emption Service : available', '25 : Automatic Answer for eMLPP : available', '27 : GSM Access : available', '28 : Data download via SMS-PP : available', '29 : Data download via SMS-CB : available', '32 : RUN AT COMMAND command : available', "33 : shall be set to '1' : available", '34 : Enabled Services Table : available', '35 : APN Control List (ACL) : available', '38 : GSM security context  : available', '39 : CPBCCH Information : available', '40 : Investigation Scan : available', '42 : Operator controlled PLMN selector with Access Technology : available', '43 : HPLMN selector with Access Technology : available', '44 : Extension 5 : available', '45 : PLMN Network Name : available', '46 : Operator PLMN List : available', '51 : Service Provider Display Information : available', '60 : User Controlled PLMN selector for I-WLAN access : available', '81 : Home I-WLAN Specific Identifier List : available', '82 : I-WLAN Equivalent HPLMN Presentation Indication : available', '83 : I-WLAN HPLMN Priority Indication : available', '84 : I-WLAN Last Registered PLMN : available', '85 : EPS Mobility Management Information : available', '86 : Allowed CSG Lists and corresponding indications : available', '87 : Call control on EPS PDN connection by USIM : available', '88 : HPLMN Direct Access : available', '89 : eCall Data : available', '90 : Operator CSG Lists and corresponding indications : available', '93 : Communication Control for IMS by USIM : available', '94 : Extended Terminal Applications : available', '122 : 5GS Mobility Management Information : available', '123 : 5G Security Parameters : available']

It should theoretically work with the SIM class as well, but it hasn't been tested.

@Nementon Nementon force-pushed the feature/usim-via-modem-at-cmds-support branch from c9c7346 to 980c0c0 Compare March 2, 2024 23:50
@mitshell
Copy link
Owner

mitshell commented Mar 9, 2024

Thanks for proposing.
Not easy to review the incremental commits however. I've checked on your branch.

The ModemCardRequest has kind of a weird initialization routine : 2 distinct exclusive args (at_client and modem_device_path), an int timeout which is passed straight in a float function, cardType which is unused and readers set into _readers attribute but seems unused afterall too.
Similarly, the transform arg in ATClientClient.transmit looks strange, as the caller could simply apply it without passing it as an argument.

Will need more time to check and eventually fix / simplify the new classes. Feel free to rebase and / or propose some simplifications on your side.

@p1-ra
Copy link

p1-ra commented Mar 9, 2024

The ModemCardRequest has kind of a weird initialization routine : 2 distinct exclusive args (at_client and modem_device_path)

The idea is to either be able to pass the at_client as dependency, in order to provide a specialization class instead of using provided ATCommandClient or just specifyng the model path to use the default implementation.

It could be factorized to only support at_client, but for simplicity and to avoid to have and import/init the ATCommandClient, I kept the option to directly pass the modem device path.

Similarly, the transform arg in ATClientClient.transmit looks strange, as the caller could simply apply it without passing it as an argument.

Same idea as the passing the at_client as dependency, here is to be open for extension, to let the consumer return a custom formatted data. Default is to return the raw string result, here the ModemCardRequest will transform it to the format as orginally returned by pyserial CardService

an int timeout which is passed straight in a float function, cardType which is unused and readers set into _readers attribute but seems unused afterall too.

ModemCardRequest implement multiple interface exposed by the pyscard Cardservice, for ease (definitely over engineering there), this parameters is only used for compatibility but is definitely not used. Not sure what is it purpose on the real Cardservice, but you know, it just works ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants