laforge has uploaded this change for review. ( https://gerrit.osmocom.org/c/pysim/+/38897?usp=email )
Change subject: esim.saip: Compute number of records from efFileSize and record_len
......................................................................
esim.saip: Compute number of records from efFileSize and record_len
If we know the efFileSize and record_len, but Fcp doesn't contain
the number of records, we can simply compute it.
Change-Id: I0cc8e7241e37ee23df00c2622422904e7ccdca77
---
M pySim/esim/saip/__init__.py
1 file changed, 5 insertions(+), 2 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/pysim refs/changes/97/38897/1
diff --git a/pySim/esim/saip/__init__.py b/pySim/esim/saip/__init__.py
index 6707802..3490f64 100644
--- a/pySim/esim/saip/__init__.py
+++ b/pySim/esim/saip/__init__.py
@@ -276,12 +276,15 @@
self.shareable = fdb_dec['shareable']
if fdb_dec['file_type'] == 'working_ef':
efFileSize = fileDescriptor.get('efFileSize', None)
- if efFileSize:
- self._file_size = self._decode_file_size(efFileSize)
if fd_dec['num_of_rec']:
self.nb_rec = fd_dec['num_of_rec']
if fd_dec['record_len']:
self.rec_len = fd_dec['record_len']
+ if efFileSize:
+ self._file_size = self._decode_file_size(efFileSize)
+ if self.rec_len and self.nb_rec == None:
+ # compute the number of records from file size and record length
+ self.nb_rec = self._file_size // self.rec_len
if fdb_dec['structure'] == 'linear_fixed':
self.file_type = 'LF'
elif fdb_dec['structure'] == 'cyclic':
--
To view, visit https://gerrit.osmocom.org/c/pysim/+/38897?usp=email
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email
Gerrit-MessageType: newchange
Gerrit-Project: pysim
Gerrit-Branch: master
Gerrit-Change-Id: I0cc8e7241e37ee23df00c2622422904e7ccdca77
Gerrit-Change-Number: 38897
Gerrit-PatchSet: 1
Gerrit-Owner: laforge <laforge(a)osmocom.org>
laforge has uploaded this change for review. ( https://gerrit.osmocom.org/c/pysim/+/38895?usp=email )
Change subject: esim.saip: Fix parsing/generating fillPattern + repeatPattern
......................................................................
esim.saip: Fix parsing/generating fillPattern + repeatPattern
So far we only thought of default filling coming from a template.
However, filling can happen from the Fcp, and we need to properly parse
and [re-]encode that information.
Change-Id: Iff339cbe841112a01c9c617f43b0e69df2521b51
Related: OS#6643
---
M pySim/esim/saip/__init__.py
1 file changed, 13 insertions(+), 14 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/pysim refs/changes/95/38895/1
diff --git a/pySim/esim/saip/__init__.py b/pySim/esim/saip/__init__.py
index 658810a..3c46ef8 100644
--- a/pySim/esim/saip/__init__.py
+++ b/pySim/esim/saip/__init__.py
@@ -116,6 +116,8 @@
self.high_update: bool = False
self.shareable: bool = True
self.df_name = None
+ self.fill_pattern = None
+ self.fill_pattern_repeat = False
# apply some defaults from profile
if self.template:
self.from_template(self.template)
@@ -174,8 +176,6 @@
self.fid = template.fid
self.sfi = template.sfi
self.arr = template.arr
- #self.default_val = template.default_val
- #self.default_val_repeat = template.default_val_repeat
if hasattr(template, 'rec_len'):
self.rec_len = template.rec_len
else:
@@ -234,14 +234,11 @@
fileDescriptor['fileDescriptor'] = build_construct(FileDescriptor._construct, fd_dict)
if self.high_update:
pefi['specialFileInformation'] = b'\x80' # TS 102 222 Table 5
- try:
- if self.template and self.template.default_val_repeat:
- pefi['repeatPattern'] = self.template.expand_default_value_pattern()
- elif self.template and self.template.default_val:
- pefi['fillPattern'] = self.template.expand_default_value_pattern()
- except ValueError:
- # ignore this here as without a file or record length we cannot do this
- pass
+ if self.fill_pattern:
+ if not self.fill_pattern_repeat:
+ pefi['fillPattern'] = self.fill_pattern
+ else:
+ pefi['repeatPattern'] = self.fill_pattern
if len(pefi.keys()):
# TODO: When overwriting the default "proprietaryEFInfo" for a template EF for which a
# default fill or repeat pattern is defined; it is hence recommended to provide the
@@ -292,11 +289,13 @@
specialFileInformation = pefi.get('specialFileInformation', None)
if specialFileInformation:
if specialFileInformation[0] & 0x80:
- self.hihgi_update = True
+ self.high_update = True
if 'repeatPattern' in pefi:
- self.repeat_pattern = pefi['repeatPattern']
- if 'defaultPattern' in pefi:
- self.repeat_pattern = pefi['defaultPattern']
+ self.fill_pattern = pefi['repeatPattern']
+ self.fill_pattern_repeat = True
+ if 'fillPattern' in pefi:
+ self.fill_pattern = pefi['fillPattern']
+ self.fill_pattern_repeat = False
elif fdb_dec['file_type'] == 'df':
# only set it, if an earlier call to from_template() didn't alrady set it, as
# the template can differentiate between MF, DF and ADF (unlike FDB)
--
To view, visit https://gerrit.osmocom.org/c/pysim/+/38895?usp=email
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email
Gerrit-MessageType: newchange
Gerrit-Project: pysim
Gerrit-Branch: master
Gerrit-Change-Id: Iff339cbe841112a01c9c617f43b0e69df2521b51
Gerrit-Change-Number: 38895
Gerrit-PatchSet: 1
Gerrit-Owner: laforge <laforge(a)osmocom.org>
laforge has uploaded this change for review. ( https://gerrit.osmocom.org/c/pysim/+/38898?usp=email )
Change subject: esim.saip: Fix computation of file content
......................................................................
esim.saip: Fix computation of file content
When generating the file content (body), we need to proceed in the
following order:
1a) If FCP contains fillPattern/repeatPattern, compute file content from those
1b) If FCP doesn't contain fillPattern/repeatPattern but template
exists, compute file content from template
2) Apply any fillFileConten / fillFileOffset from the SAIP File on top
of the above
Change-Id: I822bb5fbec11a3be35910a496af7168458fd949c
Closes: #6642
---
M pySim/esim/saip/__init__.py
M pySim/ts_102_222.py
2 files changed, 27 insertions(+), 4 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/pysim refs/changes/98/38898/1
diff --git a/pySim/esim/saip/__init__.py b/pySim/esim/saip/__init__.py
index 3490f64..355e6b9 100644
--- a/pySim/esim/saip/__init__.py
+++ b/pySim/esim/saip/__init__.py
@@ -18,6 +18,7 @@
import logging
import abc
import io
+import os
from typing import Tuple, List, Optional, Dict, Union
from collections import OrderedDict
import asn1tools
@@ -25,6 +26,7 @@
from osmocom.tlv import BER_TLV_IE, bertlv_parse_tag, bertlv_parse_len
from osmocom.construct import build_construct, parse_construct, GreedyInteger
+from pySim import ts_102_222
from pySim.utils import dec_imsi
from pySim.ts_102_221 import FileDescriptor
from pySim.filesystem import CardADF, Path
@@ -352,18 +354,29 @@
ret += self.file_content_to_tuples()
return ret
- @staticmethod
- def file_content_from_tuples(l: List[Tuple]) -> Optional[bytes]:
+ def expand_fill_pattern(self) -> bytes:
+ """Expand the fill/repeat pattern as per TS 102 222 Section 6.3.2.2.2"""
+ return ts_102_222.expand_pattern(self.fill_pattern, self.fill_pattern_repeat, self.file_size)
+
+ def file_content_from_tuples(self, l: List[Tuple]) -> Optional[bytes]:
"""linearize a list of fillFileContent / fillFileOffset tuples into a stream of bytes."""
stream = io.BytesIO()
+ # Providing file content within "fillFileContent" / "fillFileOffset" shall have the same effect as
+ # creating a file with a fill/repeat pattern and thereafter updating the content via Update.
+ # Step 1: Fill with pattern from Fcp or Template
+ if self.fill_pattern:
+ stream.write(self.expand_fill_pattern())
+ elif self.template and self.template.default_val:
+ stream.write(self.template.expand_default_value_pattern(self.file_size))
+ stream.seek(0)
+ # then process the fillFileContent/fillFileOffset
for k, v in l:
if k == 'doNotCreate':
return None
if k == 'fileDescriptor':
pass
elif k == 'fillFileOffset':
- # FIXME: respect the fillPattern!
- stream.write(b'\xff' * v)
+ stream.seek(v, os.SEEK_CUR)
elif k == 'fillFileContent':
stream.write(v)
else:
diff --git a/pySim/ts_102_222.py b/pySim/ts_102_222.py
index e54c196..74eb2c3 100644
--- a/pySim/ts_102_222.py
+++ b/pySim/ts_102_222.py
@@ -25,6 +25,16 @@
from pySim.ts_102_221 import *
+def expand_pattern(pattern: bytes, repeat: bool, size: int) -> bytes:
+ """Expand the fill/repeat pattern as per TS 102 222 Section 6.3.2.2.2 Tags C1/C2."""
+ if not repeat:
+ pad_len = size - len(pattern)
+ return pattern + pattern[-1:] * pad_len
+ else:
+ count = size // len(pattern)
+ part_len = size - count * len(pattern)
+ return pattern * count + pattern[:part_len]
+
@with_default_category('TS 102 222 Administrative Commands')
class Ts102222Commands(CommandSet):
"""Administrative commands for telecommunication applications."""
--
To view, visit https://gerrit.osmocom.org/c/pysim/+/38898?usp=email
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email
Gerrit-MessageType: newchange
Gerrit-Project: pysim
Gerrit-Branch: master
Gerrit-Change-Id: I822bb5fbec11a3be35910a496af7168458fd949c
Gerrit-Change-Number: 38898
Gerrit-PatchSet: 1
Gerrit-Owner: laforge <laforge(a)osmocom.org>
Attention is currently required from: pespin.
Hello Jenkins Builder,
I'd like you to reexamine a change. Please visit
https://gerrit.osmocom.org/c/libosmo-netif/+/38894?usp=email
to look at the new patch set (#2).
The following approvals got outdated and were removed:
Verified-1 by Jenkins Builder
Change subject: stream_srv: Add osmo_stream_srv_link_set_{ip_dscp,priority}() APIs
......................................................................
stream_srv: Add osmo_stream_srv_link_set_{ip_dscp,priority}() APIs
Change-Id: Iacb6b72a05055820253eaaa04850637dd2fc20e9
---
M TODO-RELEASE
M include/osmocom/netif/stream.h
M src/stream_srv.c
3 files changed, 50 insertions(+), 1 deletion(-)
git pull ssh://gerrit.osmocom.org:29418/libosmo-netif refs/changes/94/38894/2
--
To view, visit https://gerrit.osmocom.org/c/libosmo-netif/+/38894?usp=email
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email
Gerrit-MessageType: newpatchset
Gerrit-Project: libosmo-netif
Gerrit-Branch: master
Gerrit-Change-Id: Iacb6b72a05055820253eaaa04850637dd2fc20e9
Gerrit-Change-Number: 38894
Gerrit-PatchSet: 2
Gerrit-Owner: pespin <pespin(a)sysmocom.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Attention: pespin <pespin(a)sysmocom.de>
pespin has uploaded this change for review. ( https://gerrit.osmocom.org/c/libosmo-netif/+/38894?usp=email )
Change subject: stream_cli: Add osmo_stream_srv_link_set_{ip_dscp,priority}() APIs
......................................................................
stream_cli: Add osmo_stream_srv_link_set_{ip_dscp,priority}() APIs
Change-Id: Iacb6b72a05055820253eaaa04850637dd2fc20e9
---
M TODO-RELEASE
M include/osmocom/netif/stream.h
M src/stream_srv.c
3 files changed, 48 insertions(+), 1 deletion(-)
git pull ssh://gerrit.osmocom.org:29418/libosmo-netif refs/changes/94/38894/1
diff --git a/TODO-RELEASE b/TODO-RELEASE
index 15f995e..4f59788 100644
--- a/TODO-RELEASE
+++ b/TODO-RELEASE
@@ -7,4 +7,4 @@
# If any interfaces have been added since the last public release: c:r:a + 1.
# If any interfaces have been removed or changed since the last public release: c:r:0.
#library what description / commit summary line
-libosmo-netif add API osmo_stream_cli_set_{ip_dscp,priority}()
+libosmo-netif add API osmo_stream_cli_set_{ip_dscp,priority}(), osmo_stream_srv_link_set_{ip_dscp,priority}()
diff --git a/include/osmocom/netif/stream.h b/include/osmocom/netif/stream.h
index 96d8bbf..6edf915 100644
--- a/include/osmocom/netif/stream.h
+++ b/include/osmocom/netif/stream.h
@@ -70,6 +70,8 @@
void osmo_stream_srv_link_set_name(struct osmo_stream_srv_link *link, const char *name);
const char *osmo_stream_srv_link_get_name(const struct osmo_stream_srv_link *link);
void osmo_stream_srv_link_set_nodelay(struct osmo_stream_srv_link *link, bool nodelay);
+int osmo_stream_srv_link_set_priority(struct osmo_stream_srv_link *link, int sk_prio);
+int osmo_stream_srv_link_set_ip_dscp(struct osmo_stream_srv_link *link, uint8_t ip_dscp);
void osmo_stream_srv_link_set_addr(struct osmo_stream_srv_link *link, const char *addr);
int osmo_stream_srv_link_set_addrs(struct osmo_stream_srv_link *link, const char **addr, size_t addrcnt);
void osmo_stream_srv_link_set_port(struct osmo_stream_srv_link *link, uint16_t port);
diff --git a/src/stream_srv.c b/src/stream_srv.c
index a600ad9..ced0e05 100644
--- a/src/stream_srv.c
+++ b/src/stream_srv.c
@@ -148,6 +148,24 @@
goto error_close_socket;
}
+ if (link->ip_dscp > 0) {
+ ret = osmo_sock_set_dscp(sock_fd, link->ip_dscp);
+ if (ret < 0) {
+ LOGSLNK(link, LOGL_ERROR, "set_ip_dscp(%u): failed setsockopt err=%d\n",
+ link->ip_dscp, errno);
+ goto error_close_socket;
+ }
+ }
+
+ if (link->sk_prio > 0) {
+ ret = osmo_sock_set_priority(sock_fd, link->sk_prio);
+ if (ret < 0) {
+ LOGSLNK(link, LOGL_ERROR, "set_priority(%u): failed setsockopt err=%d\n",
+ link->sk_prio, errno);
+ goto error_close_socket;
+ }
+ }
+
if (!link->accept_cb) {
ret = -ENOTSUP;
goto error_close_socket;
@@ -224,6 +242,33 @@
link->flags &= ~OSMO_STREAM_SRV_F_NODELAY;
}
+/*! Set the priority value of the stream socket.
+ * Setting this will automatically set the socket priority
+ * option on any socket established via this server link, before
+ * calling the accept_cb().
+ * \param[in] link server link whose sockets are to be configured
+ * \param[in] sk_prio priority value. Values outside 0..6 require CAP_NET_ADMIN.
+ * \return negative on error, 0 on success
+ */
+int osmo_stream_srv_link_set_priority(struct osmo_stream_srv_link *link, int sk_prio)
+{
+ link->sk_prio = sk_prio;
+ return 0;
+}
+
+/*! Set the DSCP (differentiated services code point) of the stream socket.
+ * Setting this will automatically set the IP DSCP option on any socket on any
+ * socket established via this server link, before calling the accept_cb().
+ * \param[in] link server link whose sockets are to be configured
+ * \param[in] ip_dscp DSCP value. Value range 0..63.
+ * \return negative on error, 0 on success
+ */
+int osmo_stream_srv_link_set_ip_dscp(struct osmo_stream_srv_link *link, uint8_t ip_dscp)
+{
+ link->ip_dscp = ip_dscp;
+ return 0;
+}
+
/*! Set the local address to which we bind.
* Any changes to this setting will only become active upon next (re)connect.
* \param[in] link Stream Server Link to modify
--
To view, visit https://gerrit.osmocom.org/c/libosmo-netif/+/38894?usp=email
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email
Gerrit-MessageType: newchange
Gerrit-Project: libosmo-netif
Gerrit-Branch: master
Gerrit-Change-Id: Iacb6b72a05055820253eaaa04850637dd2fc20e9
Gerrit-Change-Number: 38894
Gerrit-PatchSet: 1
Gerrit-Owner: pespin <pespin(a)sysmocom.de>
pespin has uploaded this change for review. ( https://gerrit.osmocom.org/c/libosmo-netif/+/38893?usp=email )
Change subject: stream_cli: Announce failed connect() if reconnect is disabled
......................................................................
stream_cli: Announce failed connect() if reconnect is disabled
One of the use cases of disabling reconnect in osmo_stream_cli is
because the user of the stream wants to control the reconnect based on
upper layer contexts. In this case, though, if there's a failure during
connect() time, the user won't get any notification and hence stay
disconnected forever. Instead, inform the user through the
disconnect_cb().
Change-Id: I69a5f7c3c7cea97d31e2fa03e8c32ce806285eb6
---
M src/stream_cli.c
1 file changed, 4 insertions(+), 1 deletion(-)
git pull ssh://gerrit.osmocom.org:29418/libosmo-netif refs/changes/93/38893/1
diff --git a/src/stream_cli.c b/src/stream_cli.c
index 25dda4f..807f062 100644
--- a/src/stream_cli.c
+++ b/src/stream_cli.c
@@ -207,7 +207,10 @@
cli->state = STREAM_CLI_STATE_CLOSED;
- if (old_state == STREAM_CLI_STATE_CONNECTED) {
+ /* If conn was established, notify the disconnection to the user:
+ * Also, if reconnect is disabled by user, notify the user that connect() failed: */
+ if (old_state == STREAM_CLI_STATE_CONNECTED ||
+ (old_state == STREAM_CLI_STATE_CONNECTING && cli->reconnect_timeout < 0)) {
LOGSCLI(cli, LOGL_DEBUG, "connection closed\n");
if (cli->disconnect_cb)
cli->disconnect_cb(cli);
--
To view, visit https://gerrit.osmocom.org/c/libosmo-netif/+/38893?usp=email
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email
Gerrit-MessageType: newchange
Gerrit-Project: libosmo-netif
Gerrit-Branch: master
Gerrit-Change-Id: I69a5f7c3c7cea97d31e2fa03e8c32ce806285eb6
Gerrit-Change-Number: 38893
Gerrit-PatchSet: 1
Gerrit-Owner: pespin <pespin(a)sysmocom.de>