This is merely a historical archive of years 2008-2021, before the migration to mailman3.
A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.
Max gerrit-no-reply at lists.osmocom.orgReview at https://gerrit.osmocom.org/658 Add python functions to get/set ctrl variables Add get_var and set_var functions which handle requested variable while checking for proper response and id. Split header handling into separate function. Change-Id: I08705963c277bd93a011193dd7451a626d606c21 Related: OS#1646 --- M openbsc/contrib/bsc_control.py 1 file changed, 31 insertions(+), 4 deletions(-) git pull ssh://gerrit.osmocom.org:29418/openbsc refs/changes/58/658/1 diff --git a/openbsc/contrib/bsc_control.py b/openbsc/contrib/bsc_control.py index 4fc8b4d..e7793b9 100755 --- a/openbsc/contrib/bsc_control.py +++ b/openbsc/contrib/bsc_control.py @@ -10,15 +10,20 @@ def prefix_ipa_ctrl_header(data): return struct.pack(">HBB", len(data)+1, 0xee, 0) + data +def ipa_ctrl_header(header): + (plen, ipa_proto, osmo_proto) = struct.unpack(">HBB", header) + if (ipa_proto != 0xee or osmo_proto != 0): + return None + return plen + def remove_ipa_ctrl_header(data): if (len(data) < 4): raise BaseException("Answer too short!") - (plen, ipa_proto, osmo_proto) = struct.unpack(">HBB", data[:4]) + plen = ipa_ctrl_header(data[:4]) + if (None == plen): + raise BaseException("Wrong protocol in answer!") if (plen + 3 > len(data)): print "Warning: Wrong payload length (expected %i, got %i)" % (plen, len(data) - 3) - if (ipa_proto != 0xee or osmo_proto != 0): - raise BaseException("Wrong protocol in answer!") - return data[4:plen+3], data[plen+3:] def connect(host, port): @@ -44,6 +49,28 @@ getmsg = "GET %s %s" %(op_id, var) send(sck, getmsg) +def do_set_get(sck, var, is_get = True, value = None): + r = random.randint(1, sys.maxint) + if (is_get): + s = 'GET_REPLY' + do_get(var, r, sck) + else: + s = 'SET_REPLY' + do_set(var, value, r, sck) + (answer, data) = remove_ipa_ctrl_header(sck.recv(4096)) + x = answer.split() + if (s == x[0] and str(r) == x[1] and var == x[2]): + if (not is_get and value != x[3]): + return None + return x[3] + return None + +def set_var(sck, var, val): + return do_set_get(sck, var, False, val) + +def get_var(sck, var): + return do_set_get(sck, var) + if __name__ == '__main__': random.seed() -- To view, visit https://gerrit.osmocom.org/658 To unsubscribe, visit https://gerrit.osmocom.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I08705963c277bd93a011193dd7451a626d606c21 Gerrit-PatchSet: 1 Gerrit-Project: openbsc Gerrit-Branch: master Gerrit-Owner: Max <msuraev at sysmocom.de>