[M] Change in pysim[master]: pySim/cat: Fix contruct for Address class/IE

2024-05-22 Thread Jenkins Builder
Attention is currently required from: laforge.

Jenkins Builder has posted comments on this change. ( 
https://gerrit.osmocom.org/c/pysim/+/36839?usp=email )

Change subject: pySim/cat: Fix contruct for Address class/IE
..


Patch Set 2:

(1 comment)

File smpp_ota_apdu2.py:

Robot Comment from checkpatch (run ID jenkins-gerrit-lint-16251):
https://gerrit.osmocom.org/c/pysim/+/36839/comment/da9be05c_a5613ab5
PS2, Line 97:
trailing whitespace



--
To view, visit https://gerrit.osmocom.org/c/pysim/+/36839?usp=email
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings

Gerrit-Project: pysim
Gerrit-Branch: master
Gerrit-Change-Id: Idf8326298cab7ebc68b09c7e829bfc2061222f51
Gerrit-Change-Number: 36839
Gerrit-PatchSet: 2
Gerrit-Owner: laforge 
Gerrit-Reviewer: Jenkins Builder
Gerrit-CC: fixeria 
Gerrit-Attention: laforge 
Gerrit-Comment-Date: Wed, 22 May 2024 16:17:42 +
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Gerrit-MessageType: comment


[M] Change in pysim[master]: pySim/cat: Fix contruct for Address class/IE

2024-05-16 Thread fixeria
Attention is currently required from: laforge.

fixeria has posted comments on this change. ( 
https://gerrit.osmocom.org/c/pysim/+/36839?usp=email )

Change subject: pySim/cat: Fix contruct for Address class/IE
..


Patch Set 1:

(1 comment)

File smpp_ota_apdu2.py:

https://gerrit.osmocom.org/c/pysim/+/36839/comment/14516f52_d27fa5dc
PS1, Line 1: #!/usr/bin/env python3
unrelated to this commit?



--
To view, visit https://gerrit.osmocom.org/c/pysim/+/36839?usp=email
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings

Gerrit-Project: pysim
Gerrit-Branch: master
Gerrit-Change-Id: Idf8326298cab7ebc68b09c7e829bfc2061222f51
Gerrit-Change-Number: 36839
Gerrit-PatchSet: 1
Gerrit-Owner: laforge 
Gerrit-Reviewer: Jenkins Builder
Gerrit-CC: fixeria 
Gerrit-Attention: laforge 
Gerrit-Comment-Date: Thu, 16 May 2024 09:05:39 +
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Gerrit-MessageType: comment


[M] Change in pysim[master]: pySim/cat: Fix contruct for Address class/IE

2024-05-15 Thread Jenkins Builder
Jenkins Builder has posted comments on this change. ( 
https://gerrit.osmocom.org/c/pysim/+/36839?usp=email )

Change subject: pySim/cat: Fix contruct for Address class/IE
..


Patch Set 1:

(1 comment)

File smpp_ota_apdu2.py:

Robot Comment from checkpatch (run ID jenkins-gerrit-lint-16143):
https://gerrit.osmocom.org/c/pysim/+/36839/comment/24981309_89352c25
PS1, Line 97:
trailing whitespace



--
To view, visit https://gerrit.osmocom.org/c/pysim/+/36839?usp=email
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings

Gerrit-Project: pysim
Gerrit-Branch: master
Gerrit-Change-Id: Idf8326298cab7ebc68b09c7e829bfc2061222f51
Gerrit-Change-Number: 36839
Gerrit-PatchSet: 1
Gerrit-Owner: laforge 
Gerrit-CC: Jenkins Builder
Gerrit-Comment-Date: Thu, 16 May 2024 06:34:07 +
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Gerrit-MessageType: comment


[M] Change in pysim[master]: pySim/cat: Fix contruct for Address class/IE

2024-05-15 Thread laforge
laforge has uploaded this change for review. ( 
https://gerrit.osmocom.org/c/pysim/+/36839?usp=email )


Change subject: pySim/cat: Fix contruct for Address class/IE
..

pySim/cat: Fix contruct for Address class/IE

Something like "this._.total_len-1" only works during decode. Let's
use GreedyBytes instead, working for encode and decode.

Change-Id: Idf8326298cab7ebc68b09c7e829bfc2061222f51
---
M pySim/cat.py
A smpp_ota_apdu2.py
2 files changed, 116 insertions(+), 1 deletion(-)



  git pull ssh://gerrit.osmocom.org:29418/pysim refs/changes/39/36839/1

diff --git a/pySim/cat.py b/pySim/cat.py
index 1dff194..fdaf8f3 100644
--- a/pySim/cat.py
+++ b/pySim/cat.py
@@ -32,7 +32,7 @@
 # TS 102 223 Section 8.1
 class Address(COMPR_TLV_IE, tag=0x06):
 _construct = Struct('ton_npi'/Int8ub,
-'call_number'/BcdAdapter(Bytes(this._.total_len-1)))
+'call_number'/BcdAdapter(GreedyBytes))

 # TS 102 223 Section 8.2
 class AlphaIdentifier(COMPR_TLV_IE, tag=0x05):
diff --git a/smpp_ota_apdu2.py b/smpp_ota_apdu2.py
new file mode 100755
index 000..60f7863
--- /dev/null
+++ b/smpp_ota_apdu2.py
@@ -0,0 +1,103 @@
+#!/usr/bin/env python3
+import logging
+import sys
+from pprint import pprint as pp
+
+from pySim.ota import OtaKeyset, OtaDialectSms
+from pySim.utils import b2h, h2b
+
+import smpplib.gsm
+import smpplib.client
+import smpplib.consts
+
+logger = logging.getLogger(__name__)
+
+# if you want to know what's happening
+logging.basicConfig(level='DEBUG')
+
+class Foo:
+def smpp_rx_handler(self, pdu):
+sys.stdout.write('delivered {}\n'.format(pdu.receipted_message_id))
+if pdu.short_message:
+dec = self.ota_dialect.decode_resp(self.ota_keyset, self.spi, 
pdu.short_message)
+pp(dec)
+return None
+
+def __init__(self):
+# Two parts, UCS2, SMS with UDH
+#parts, encoding_flag, msg_type_flag = smpplib.gsm.make_parts(u'Привет 
мир!\n'*10)
+
+client = smpplib.client.Client('localhost', 2775, 
allow_unknown_opt_params=True)
+
+# Print when obtain message_id
+client.set_message_sent_handler(
+lambda pdu: sys.stdout.write('sent {} {}\n'.format(pdu.sequence, 
pdu.message_id)))
+#client.set_message_received_handler(
+#lambda pdu: sys.stdout.write('delivered 
{}\n'.format(pdu.receipted_message_id)))
+client.set_message_received_handler(self.smpp_rx_handler)
+
+client.connect()
+client.bind_transceiver(system_id='test', password='test')
+
+self.client = client
+
+if False:
+KIC1 = h2b('000102030405060708090a0b0c0d0e0f')
+KID1 = h2b('101112131415161718191a1b1c1d1e1f')
+self.ota_keyset = OtaKeyset(algo_crypt='aes_cbc', kic_idx=1, 
kic=KIC1,
+algo_auth='aes_cmac', kid_idx=1, 
kid=KID1)
+self.tar = h2b('01') # ISD-R according to Annex H of SGP.02
+#self.tar = h2b('02') # ECASD according to Annex H of SGP.02
+
+if True:
+KIC1 = h2b('4BE2D58A1FA7233DD723B3C70996E6E6')
+KID1 = h2b('4a664208eba091d32c4ecbc299da1f34')
+self.ota_keyset = OtaKeyset(algo_crypt='triple_des_cbc2', 
kic_idx=1, kic=KIC1,
+algo_auth='triple_des_cbc2', 
kid_idx=1, kid=KID1)
+#KIC3 = h2b('A4074D8E1FE69B484A7E62682ED09B51')
+#KID3 = h2b('41FF1033910112DB4EBEBB7807F939CD')
+#self.ota_keyset = OtaKeyset(algo_crypt='triple_des_cbc2', 
kic_idx=3, kic=KIC3,
+#algo_auth='triple_des_cbc2', 
kid_idx=3, kid=KID3)
+#self.tar = h2b('B00011') # USIM RFM
+self.tar = h2b('00') # RAM
+
+self.ota_dialect = OtaDialectSms()
+self.spi = {'counter':'no_counter', 'ciphering':True, 'rc_cc_ds': 
'cc', 'por_in_submit':False,
+'por_shall_be_ciphered':True, 'por_rc_cc_ds': 'cc', 'por': 
'por_required'}
+
+
+def tx_sms_tpdu(self, tpdu: bytes):
+self.client.send_message(
+source_addr_ton=smpplib.consts.SMPP_TON_INTL,
+#source_addr_npi=smpplib.consts.SMPP_NPI_ISDN,
+# Make sure it is a byte string, not unicode:
+source_addr='12',
+
+dest_addr_ton=smpplib.consts.SMPP_TON_INTL,
+#dest_addr_npi=smpplib.consts.SMPP_NPI_ISDN,
+# Make sure thease two params are byte strings, not unicode:
+destination_addr='23',
+short_message=tpdu,
+
+data_coding=smpplib.consts.SMPP_ENCODING_BINARY,
+esm_class=smpplib.consts.SMPP_GSMFEAT_UDHI,
+protocol_id=0x7f,
+#registered_delivery=True,
+)
+
+def tx_c_apdu(self, apdu: bytes):
+logger.info("C-APDU: %s" % b2h(apdu))
+# translate to Secured OTA RFM
+secured = sel