Hoernchen has uploaded this change for review.

View Change

bip: report a location in PROVIDE LOCAL INFORMATION

TS 102 223 6.8.7: TERMINAL RESPONSE shall contain the data object the
command qualifier (6.6.15) asked for.
The card always asks for location information, so at least answer 00,
with the GERAN form of TS 131.111 8.19.1, PLMN 262-01.

Do not answer "terminal currently unable to process - no service"...

Change-Id: I53547da2ea9f0a4ea7a4dd032985a546f2d4277f
---
M pySim/bip.py
M pySim/cat.py
M tests/unittests/test_bip_relay.py
3 files changed, 56 insertions(+), 4 deletions(-)

git pull ssh://gerrit.osmocom.org:29418/pysim refs/changes/65/43565/1
diff --git a/pySim/bip.py b/pySim/bip.py
index b25fe5f..1880bd0 100644
--- a/pySim/bip.py
+++ b/pySim/bip.py
@@ -42,10 +42,16 @@
from pySim.cat import (ProactiveCommand, SendShortMessage, SMS_TPDU, SMSPPDownload,
BearerDescription, DeviceIdentities, Address, OtherAddress,
UiccTransportLevel, BufferSize, ChannelStatus, ChannelData,
- ChannelDataLength, EventList, EventDownload, Result)
+ ChannelDataLength, EventList, EventDownload, Result,
+ CommandDetails, LocationInformation)

logger = logging.getLogger(__name__)

+# PROVIDE LOCAL INFORMATION location, GERAN TS 31.111 8.19.1
+# - 3 byte PLMN of TS 24.008 10.5.1.3 -> 262-01
+# - 2 byte LAC and a 2 byte cid.
+DEFAULT_LOCATION = h2b('62f21000010001')
+

def terminal_profile(num_channels: int = 7) -> bytes:
"""TERMINAL PROFILE for what we implement, TS 102 223 5.2 and annex T.
@@ -226,7 +232,7 @@
class Proact(ProactiveHandler):
#def __init__(self, smpp_factory):
# self.smpp_factory = smpp_factory
- def __init__(self, data_available_sink=None, sms_sink=None):
+ def __init__(self, data_available_sink=None, sms_sink=None, location: bytes = DEFAULT_LOCATION):
# data_available_sink(envelope_hex) delivers ENVELOPE EVENT DOWNLOAD
# to the card when socket data arrives
# None in card free/test mode
@@ -235,8 +241,24 @@
# onwards; pySim-smpp2sim.py hands it to its SMPP server. None -> log
# and drop.
self.sms_sink = sms_sink
+ self.location = location
self.channels = ProactChannels(on_data_available=self._on_channel_data_available)

+ def handle_ProvideLocalInformation(self, pcmd: ProactiveCommand):
+ """only location
+
+ TS 102 223 6.8.7 says TERMINAL RESPONSE to PROVIDE LOCAL INFORMATION "shall"
+ contain the data object the command qualifier (6.6.15) asked for. At least answer '00',
+ location information, usually requested.
+
+ answering "terminal currently unable to process - no service", which is a handset
+ out of coverage makes SJA5 believe it and postpones the entire session!
+ it registers a location status event, starts a ten minute timer and waits for coverage."""
+ cmd_det_ie = Proact._find_first_element_of_type(pcmd.children, CommandDetails)
+ if cmd_det_ie is not None and cmd_det_ie.decoded['command_qualifier'] == 0x00:
+ return self.prepare_response(pcmd) + [LocationInformation(decoded=self.location)]
+ return self.prepare_response(pcmd)
+
def receive_fetch(self, pcmd: ProactiveCommand):
"""Answer anything this handler has no specific handler for.

diff --git a/pySim/cat.py b/pySim/cat.py
index 8e072d8..61526d8 100644
--- a/pySim/cat.py
+++ b/pySim/cat.py
@@ -318,7 +318,9 @@

# TS 102 223 Section 8.19
class LocationInformation(COMPR_TLV_IE, tag=0x93):
- pass
+ # 8.19: coding is per access technology, and the lengths differ (TS 131.111 8.19.1-.4: GERAN 7,
+ # UTRAN/E-UTRAN 9, NG-RAN 11) with nothing in the IE to say which -> keep the value opaque.
+ _construct = GreedyBytes

class MobileIdentityAdapter(Adapter):
"""TS 124.008 section 10.5.1.4 figure 10.5.4 + table 10.5.4
diff --git a/tests/unittests/test_bip_relay.py b/tests/unittests/test_bip_relay.py
index e7229d7..5f36823 100644
--- a/tests/unittests/test_bip_relay.py
+++ b/tests/unittests/test_bip_relay.py
@@ -25,7 +25,7 @@
from pySim.cat import (ProactiveCommand, CommandDetails, DeviceIdentities,
BearerDescription, BufferSize, UiccTransportLevel,
OtherAddress, ChannelData, ChannelDataLength, ChannelStatus,
- Result)
+ Result, LocationInformation)

from pySim.bip import Proact, ProactChannels, terminal_profile

@@ -324,6 +324,34 @@
self.assertEqual(self.proact.channels.channels, {}) # channel given back


+class ProvideLocalInformationTest(unittest.TestCase):
+ """TS 102 223 6.8.7: only 00 gets a data object; the rest keeps the empty result."""
+
+ def _cmd(self, qualifier):
+ return _pcmd([
+ CommandDetails(decoded={'command_number': 1, 'type_of_command': 'provide_local_info',
+ 'command_qualifier': qualifier}).to_tlv(),
+ DeviceIdentities(decoded={'source_dev_id': 'uicc', 'dest_dev_id': 'terminal'}).to_tlv()])
+
+ def test_location(self):
+ til = Proact().handle_ProvideLocalInformation(self._cmd(0x00))
+ b''.join(x.to_tlv() for x in til)
+ self.assertEqual(_first(til, Result).decoded['general_result'], 'performed_successfully')
+ self.assertEqual(b2h(_first(til, LocationInformation).to_tlv()), '930762f21000010001')
+ self.assertEqual(b2h(_first(til, DeviceIdentities).to_tlv()), '82028281') # 6.8.2
+
+ def test_other_qualifiers_get_no_data_object(self):
+ for qualifier in (0x01, 0x03, 0x04, 0x1a):
+ with self.subTest(command_qualifier=qualifier):
+ til = Proact().handle_ProvideLocalInformation(self._cmd(qualifier))
+ b''.join(x.to_tlv() for x in til)
+ self.assertIsNone(_first(til, LocationInformation))
+
+ def test_location_is_configurable(self):
+ til = Proact(location=h2b('26f8100539')).handle_ProvideLocalInformation(self._cmd(0x00))
+ self.assertEqual(b2h(_first(til, LocationInformation).to_tlv()), '930526f8100539')
+
+
class TerminalProfileTest(unittest.TestCase):
"""TS 102 223 5.2, one bit per CAT facility"""


To view, visit change 43565. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-MessageType: newchange
Gerrit-Project: pysim
Gerrit-Branch: master
Gerrit-Change-Id: I53547da2ea9f0a4ea7a4dd032985a546f2d4277f
Gerrit-Change-Number: 43565
Gerrit-PatchSet: 1
Gerrit-Owner: Hoernchen <ewild@sysmocom.de>