From ee14fdde639e8960242f6a9adb7843b1afd43322 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 4 Feb 2026 14:32:55 +0000 Subject: [PATCH 01/18] Initial plan From 1b44380ef1a98ab05efa7efeedd9f21efd5fc5d8 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 4 Feb 2026 14:36:52 +0000 Subject: [PATCH 02/18] Add example and tests for GSMNetworks lookup Co-authored-by: nijel <212189+nijel@users.noreply.github.com> --- examples/async.py | 9 ++++ examples/network_info.py | 106 +++++++++++++++++++++++++++++++++++++++ test/test_data.py | 22 ++++++++ 3 files changed, 137 insertions(+) create mode 100644 examples/network_info.py diff --git a/examples/async.py b/examples/async.py index 485212af5..fca74733b 100644 --- a/examples/async.py +++ b/examples/async.py @@ -52,6 +52,15 @@ async def send_message_async(state_machine, number, message): async def get_network_info(worker): info = await worker.get_network_info_async() print("NetworkName:", info["NetworkName"]) + + # If NetworkName is empty, look it up in the GSMNetworks database + if not info["NetworkName"] and info["NetworkCode"]: + network_code = info["NetworkCode"] + if network_code in gammu.GSMNetworks: + print(" NetworkName (from DB):", gammu.GSMNetworks[network_code]) + else: + print(" NetworkName (from DB): Unknown network code") + print(" State:", info["State"]) print(" NetworkCode:", info["NetworkCode"]) print(" CID:", info["CID"]) diff --git a/examples/network_info.py b/examples/network_info.py new file mode 100644 index 000000000..38777bb59 --- /dev/null +++ b/examples/network_info.py @@ -0,0 +1,106 @@ +#!/usr/bin/env python +# vim: expandtab sw=4 ts=4 sts=4: +# +# Copyright © 2003 - 2018 Michal Čihař +# +# This file is part of python-gammu +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +# +""" +Example demonstrating how to get network information and look up network names. + +When GetNetworkInfo() returns an empty NetworkName, you can use the +gammu.GSMNetworks dictionary to look up the network name by its NetworkCode. +The NetworkCode is returned by the phone even when NetworkName is empty. + +This is useful because many phones don't return the network name, but the +network code can be looked up in Gammu's network database. +""" + +import sys + +import gammu + + +def get_network_info_with_name(state_machine): + """ + Get network information and look up network name if it's empty. + + The phone returns NetworkCode (e.g., "240 24") even when NetworkName + is empty. We can use gammu.GSMNetworks to look up the network name. + """ + # Get network info from phone + netinfo = state_machine.GetNetworkInfo() + + print("Network Information:") + print("=" * 50) + print(f"Network Code: {netinfo['NetworkCode']}") + print(f"Network Name (from phone): {netinfo['NetworkName']}") + + # If NetworkName is empty, look it up in the GSMNetworks database + if not netinfo['NetworkName'] and netinfo['NetworkCode']: + network_code = netinfo['NetworkCode'] + if network_code in gammu.GSMNetworks: + network_name = gammu.GSMNetworks[network_code] + print(f"Network Name (from DB): {network_name}") + else: + print(f"Network Name (from DB): Unknown network code '{network_code}'") + + print(f"State: {netinfo['State']}") + print(f"LAC: {netinfo['LAC']}") + print(f"CID: {netinfo['CID']}") + + if 'GPRS' in netinfo: + print(f"GPRS: {netinfo['GPRS']}") + + return netinfo + + +def main(): + """Main function to demonstrate network info lookup.""" + # Create state machine + state_machine = gammu.StateMachine() + + # Read configuration from default location (~/.gammurc or /etc/gammurc) + # You can also specify a config file: state_machine.ReadConfig(Filename="gammurc") + state_machine.ReadConfig() + + # Connect to phone + state_machine.Init() + + # Get and display network information with name lookup + get_network_info_with_name(state_machine) + + # You can also explore available networks in the database + print("\n" + "=" * 50) + print("Example: Browsing the GSMNetworks database") + print("=" * 50) + print(f"Total networks in database: {len(gammu.GSMNetworks)}") + + # Show a few example networks + print("\nSome example networks:") + example_codes = ["240 24", "244 05", "310 260", "234 10"] + for code in example_codes: + if code in gammu.GSMNetworks: + print(f" {code}: {gammu.GSMNetworks[code]}") + + +if __name__ == "__main__": + try: + main() + except gammu.GSMError as e: + print(f"Error: {e}") + sys.exit(1) diff --git a/test/test_data.py b/test/test_data.py index b6414ae6e..7d89e60ef 100644 --- a/test/test_data.py +++ b/test/test_data.py @@ -20,6 +20,7 @@ # import unittest +import gammu import gammu.data @@ -30,3 +31,24 @@ def test_connections(self): def test_errors(self): self.assertTrue("ERR_INSTALL_NOT_FOUND" in gammu.data.Errors) self.assertEqual(gammu.data.ErrorNumbers[73], "ERR_NETWORK_ERROR") + + def test_gsm_networks(self): + """Test that GSMNetworks dictionary is available and contains expected data.""" + # GSMNetworks should be a dictionary available from gammu module + self.assertIsInstance(gammu.GSMNetworks, dict) + # Should have at least some networks + self.assertGreater(len(gammu.GSMNetworks), 0) + # Test a known network code (Finland Elisa) + # Network code "244 05" should map to "Elisa" + if "244 05" in gammu.GSMNetworks: + self.assertEqual(gammu.GSMNetworks["244 05"], "Elisa") + + def test_gsm_countries(self): + """Test that GSMCountries dictionary is available and contains expected data.""" + # GSMCountries should be a dictionary available from gammu module + self.assertIsInstance(gammu.GSMCountries, dict) + # Should have at least some countries + self.assertGreater(len(gammu.GSMCountries), 0) + # Test a known country code (Finland) + if "244" in gammu.GSMCountries: + self.assertEqual(gammu.GSMCountries["244"], "Finland") From c7b3b0af60069aff00c93214c0e63a5d0bbb23e1 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 4 Feb 2026 14:37:41 +0000 Subject: [PATCH 03/18] Update GetNetworkInfo docstring to mention GSMNetworks lookup Co-authored-by: nijel <212189+nijel@users.noreply.github.com> --- examples/network_info.py | 0 gammu/src/gammu.c | 3 +++ 2 files changed, 3 insertions(+) mode change 100644 => 100755 examples/network_info.py diff --git a/examples/network_info.py b/examples/network_info.py old mode 100644 new mode 100755 diff --git a/gammu/src/gammu.c b/gammu/src/gammu.c index 0dbfb53d5..78b218991 100644 --- a/gammu/src/gammu.c +++ b/gammu/src/gammu.c @@ -1819,6 +1819,9 @@ static char StateMachine_GetNetworkInfo__doc__[] = "Gets network information.\n\n" "@return: Hash with information about network (NetworkName, State, NetworkCode, CID and LAC)\n" "@rtype: hash\n" +"@note: NetworkName may be empty if not provided by the phone. In such cases,\n" +" you can look up the network name using NetworkCode in the gammu.GSMNetworks\n" +" dictionary: network_name = gammu.GSMNetworks.get(network_code)\n" ; static PyObject * From dcf5785fa8d8b17d076a4e7685457beec2dfdf40 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 4 Feb 2026 14:38:45 +0000 Subject: [PATCH 04/18] Fix docstring to match example code pattern Co-authored-by: nijel <212189+nijel@users.noreply.github.com> --- gammu/src/gammu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gammu/src/gammu.c b/gammu/src/gammu.c index 78b218991..cdcac4a86 100644 --- a/gammu/src/gammu.c +++ b/gammu/src/gammu.c @@ -1821,7 +1821,7 @@ static char StateMachine_GetNetworkInfo__doc__[] = "@rtype: hash\n" "@note: NetworkName may be empty if not provided by the phone. In such cases,\n" " you can look up the network name using NetworkCode in the gammu.GSMNetworks\n" -" dictionary: network_name = gammu.GSMNetworks.get(network_code)\n" +" dictionary: if network_code in gammu.GSMNetworks: network_name = gammu.GSMNetworks[network_code]\n" ; static PyObject * From d5a164358f60d4625373ed4e6ea1946dae3b5184 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 4 Feb 2026 14:39:38 +0000 Subject: [PATCH 05/18] Complete implementation Co-authored-by: nijel <212189+nijel@users.noreply.github.com> --- _codeql_detected_source_root | 1 + 1 file changed, 1 insertion(+) create mode 120000 _codeql_detected_source_root diff --git a/_codeql_detected_source_root b/_codeql_detected_source_root new file mode 120000 index 000000000..945c9b46d --- /dev/null +++ b/_codeql_detected_source_root @@ -0,0 +1 @@ +. \ No newline at end of file From 21c7950d82d171631630bfecc91308de81032177 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 4 Feb 2026 14:39:44 +0000 Subject: [PATCH 06/18] Remove codeql artifact --- _codeql_detected_source_root | 1 - 1 file changed, 1 deletion(-) delete mode 120000 _codeql_detected_source_root diff --git a/_codeql_detected_source_root b/_codeql_detected_source_root deleted file mode 120000 index 945c9b46d..000000000 --- a/_codeql_detected_source_root +++ /dev/null @@ -1 +0,0 @@ -. \ No newline at end of file From 2efe681c6a1dec1947cf1021610751285feb75c0 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 4 Feb 2026 14:50:30 +0000 Subject: [PATCH 07/18] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- examples/async.py | 4 ++-- examples/network_info.py | 28 ++++++++++++++-------------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/examples/async.py b/examples/async.py index fca74733b..c7d5fa914 100644 --- a/examples/async.py +++ b/examples/async.py @@ -52,7 +52,7 @@ async def send_message_async(state_machine, number, message): async def get_network_info(worker): info = await worker.get_network_info_async() print("NetworkName:", info["NetworkName"]) - + # If NetworkName is empty, look it up in the GSMNetworks database if not info["NetworkName"] and info["NetworkCode"]: network_code = info["NetworkCode"] @@ -60,7 +60,7 @@ async def get_network_info(worker): print(" NetworkName (from DB):", gammu.GSMNetworks[network_code]) else: print(" NetworkName (from DB): Unknown network code") - + print(" State:", info["State"]) print(" NetworkCode:", info["NetworkCode"]) print(" CID:", info["CID"]) diff --git a/examples/network_info.py b/examples/network_info.py index 38777bb59..ca1743aab 100755 --- a/examples/network_info.py +++ b/examples/network_info.py @@ -38,34 +38,34 @@ def get_network_info_with_name(state_machine): """ Get network information and look up network name if it's empty. - + The phone returns NetworkCode (e.g., "240 24") even when NetworkName is empty. We can use gammu.GSMNetworks to look up the network name. """ # Get network info from phone netinfo = state_machine.GetNetworkInfo() - + print("Network Information:") print("=" * 50) print(f"Network Code: {netinfo['NetworkCode']}") print(f"Network Name (from phone): {netinfo['NetworkName']}") - + # If NetworkName is empty, look it up in the GSMNetworks database - if not netinfo['NetworkName'] and netinfo['NetworkCode']: - network_code = netinfo['NetworkCode'] + if not netinfo["NetworkName"] and netinfo["NetworkCode"]: + network_code = netinfo["NetworkCode"] if network_code in gammu.GSMNetworks: network_name = gammu.GSMNetworks[network_code] print(f"Network Name (from DB): {network_name}") else: print(f"Network Name (from DB): Unknown network code '{network_code}'") - + print(f"State: {netinfo['State']}") print(f"LAC: {netinfo['LAC']}") print(f"CID: {netinfo['CID']}") - - if 'GPRS' in netinfo: + + if "GPRS" in netinfo: print(f"GPRS: {netinfo['GPRS']}") - + return netinfo @@ -73,23 +73,23 @@ def main(): """Main function to demonstrate network info lookup.""" # Create state machine state_machine = gammu.StateMachine() - + # Read configuration from default location (~/.gammurc or /etc/gammurc) # You can also specify a config file: state_machine.ReadConfig(Filename="gammurc") state_machine.ReadConfig() - + # Connect to phone state_machine.Init() - + # Get and display network information with name lookup get_network_info_with_name(state_machine) - + # You can also explore available networks in the database print("\n" + "=" * 50) print("Example: Browsing the GSMNetworks database") print("=" * 50) print(f"Total networks in database: {len(gammu.GSMNetworks)}") - + # Show a few example networks print("\nSome example networks:") example_codes = ["240 24", "244 05", "310 260", "234 10"] From 09e76265a4b0c49961b97fd47aa6748e3cfb30d4 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 4 Feb 2026 15:05:58 +0000 Subject: [PATCH 08/18] Fix NetworkName to use UnicodeStringToPython for proper Unicode handling Co-authored-by: nijel <212189+nijel@users.noreply.github.com> --- gammu/src/gammu.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/gammu/src/gammu.c b/gammu/src/gammu.c index cdcac4a86..873406ec5 100644 --- a/gammu/src/gammu.c +++ b/gammu/src/gammu.c @@ -1829,6 +1829,7 @@ StateMachine_GetNetworkInfo(StateMachineObject *self, PyObject *args, PyObject * GSM_Error error; GSM_NetworkInfo netinfo; char *buffer, *packet_state; + PyObject *network_name; if (!PyArg_ParseTuple(args, "")) return NULL; @@ -1861,8 +1862,10 @@ StateMachine_GetNetworkInfo(StateMachineObject *self, PyObject *args, PyObject * case GSM_NetworkStatusUnknown: packet_state = "NetworkStatusUnknown"; break; } - return Py_BuildValue("{s:s,s:s,s:s,s:s,s:s,s:s,s:s,s:s,s:s}", - "NetworkName", netinfo.NetworkName, + network_name = UnicodeStringToPython(netinfo.NetworkName); + + return Py_BuildValue("{s:N,s:s,s:s,s:s,s:s,s:s,s:s,s:s,s:s}", + "NetworkName", network_name, "State", buffer, "PacketState", packet_state, "NetworkCode", netinfo.NetworkCode, From bf813faccb6dabb5bdd9a9920d7bbc964f494f65 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 4 Feb 2026 15:06:53 +0000 Subject: [PATCH 09/18] Add NULL check for UnicodeStringToPython result Co-authored-by: nijel <212189+nijel@users.noreply.github.com> --- gammu/src/gammu.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/gammu/src/gammu.c b/gammu/src/gammu.c index 873406ec5..c7f35d7a3 100644 --- a/gammu/src/gammu.c +++ b/gammu/src/gammu.c @@ -1863,6 +1863,8 @@ StateMachine_GetNetworkInfo(StateMachineObject *self, PyObject *args, PyObject * } network_name = UnicodeStringToPython(netinfo.NetworkName); + if (network_name == NULL) + return NULL; return Py_BuildValue("{s:N,s:s,s:s,s:s,s:s,s:s,s:s,s:s,s:s}", "NetworkName", network_name, From d884f0bd66c63d7d42b0cf3b2d396d82bc370732 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 4 Feb 2026 15:07:47 +0000 Subject: [PATCH 10/18] Co-authored-by: nijel <212189+nijel@users.noreply.github.com> --- _codeql_detected_source_root | 1 + 1 file changed, 1 insertion(+) create mode 120000 _codeql_detected_source_root diff --git a/_codeql_detected_source_root b/_codeql_detected_source_root new file mode 120000 index 000000000..945c9b46d --- /dev/null +++ b/_codeql_detected_source_root @@ -0,0 +1 @@ +. \ No newline at end of file From 0c87885719adea9d544faf38074e0c7fe9f76457 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Wed, 4 Feb 2026 16:12:05 +0100 Subject: [PATCH 11/18] Delete _codeql_detected_source_root --- _codeql_detected_source_root | 1 - 1 file changed, 1 deletion(-) delete mode 120000 _codeql_detected_source_root diff --git a/_codeql_detected_source_root b/_codeql_detected_source_root deleted file mode 120000 index 945c9b46d..000000000 --- a/_codeql_detected_source_root +++ /dev/null @@ -1 +0,0 @@ -. \ No newline at end of file From f2f9087b0bf79553902dfce91a9563eee10bed5a Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 4 Feb 2026 15:21:36 +0000 Subject: [PATCH 12/18] Add Unicode/ASCII detection for NetworkName compatibility Co-authored-by: nijel <212189+nijel@users.noreply.github.com> --- gammu/src/gammu.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/gammu/src/gammu.c b/gammu/src/gammu.c index c7f35d7a3..761327ba1 100644 --- a/gammu/src/gammu.c +++ b/gammu/src/gammu.c @@ -1862,7 +1862,21 @@ StateMachine_GetNetworkInfo(StateMachineObject *self, PyObject *args, PyObject * case GSM_NetworkStatusUnknown: packet_state = "NetworkStatusUnknown"; break; } - network_name = UnicodeStringToPython(netinfo.NetworkName); + /* Detect if NetworkName is Unicode or ASCII string. + * Unicode strings in Gammu use 2-byte encoding (little-endian). + * ASCII strings from dummy backend are regular C strings. + * Heuristic: if second byte is 0 and first byte is non-zero, it's Unicode. + * If both bytes are 0, it's empty (compatible with both). + * Otherwise, treat as ASCII for backward compatibility. + */ + if (netinfo.NetworkName[0] == 0 || (netinfo.NetworkName[0] != 0 && netinfo.NetworkName[1] == 0)) { + /* Unicode string or empty */ + network_name = UnicodeStringToPython(netinfo.NetworkName); + } else { + /* ASCII string (e.g., from dummy backend) */ + network_name = LocaleStringToPython((char *)netinfo.NetworkName); + } + if (network_name == NULL) return NULL; From 6daca53d86418e475020b7bcbb0fd282db5f9053 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 4 Feb 2026 15:22:34 +0000 Subject: [PATCH 13/18] Simplify Unicode/ASCII detection logic and improve comment Co-authored-by: nijel <212189+nijel@users.noreply.github.com> --- gammu/src/gammu.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/gammu/src/gammu.c b/gammu/src/gammu.c index 761327ba1..7c0d8e4a5 100644 --- a/gammu/src/gammu.c +++ b/gammu/src/gammu.c @@ -1865,11 +1865,10 @@ StateMachine_GetNetworkInfo(StateMachineObject *self, PyObject *args, PyObject * /* Detect if NetworkName is Unicode or ASCII string. * Unicode strings in Gammu use 2-byte encoding (little-endian). * ASCII strings from dummy backend are regular C strings. - * Heuristic: if second byte is 0 and first byte is non-zero, it's Unicode. - * If both bytes are 0, it's empty (compatible with both). - * Otherwise, treat as ASCII for backward compatibility. + * Heuristic: if second byte is 0 (empty string or Unicode pattern), use Unicode path. + * Otherwise, treat as ASCII for backward compatibility with dummy backend. */ - if (netinfo.NetworkName[0] == 0 || (netinfo.NetworkName[0] != 0 && netinfo.NetworkName[1] == 0)) { + if (netinfo.NetworkName[0] == 0 || netinfo.NetworkName[1] == 0) { /* Unicode string or empty */ network_name = UnicodeStringToPython(netinfo.NetworkName); } else { From fd597bb7e0f6c978a61419f57d12583760898bd2 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 4 Feb 2026 15:23:27 +0000 Subject: [PATCH 14/18] Co-authored-by: nijel <212189+nijel@users.noreply.github.com> --- _codeql_detected_source_root | 1 + 1 file changed, 1 insertion(+) create mode 120000 _codeql_detected_source_root diff --git a/_codeql_detected_source_root b/_codeql_detected_source_root new file mode 120000 index 000000000..945c9b46d --- /dev/null +++ b/_codeql_detected_source_root @@ -0,0 +1 @@ +. \ No newline at end of file From 38a5d09600e5ec8144f5c3a68f40adc120fc0199 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Wed, 4 Feb 2026 16:26:27 +0100 Subject: [PATCH 15/18] Delete _codeql_detected_source_root --- _codeql_detected_source_root | 1 - 1 file changed, 1 deletion(-) delete mode 120000 _codeql_detected_source_root diff --git a/_codeql_detected_source_root b/_codeql_detected_source_root deleted file mode 120000 index 945c9b46d..000000000 --- a/_codeql_detected_source_root +++ /dev/null @@ -1 +0,0 @@ -. \ No newline at end of file From 39fdec1f2ab82e9f17ad254d5870e013c4d36370 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Wed, 4 Feb 2026 16:38:05 +0100 Subject: [PATCH 16/18] Revert "Simplify Unicode/ASCII detection logic and improve comment" This reverts commit 6daca53d86418e475020b7bcbb0fd282db5f9053. --- gammu/src/gammu.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/gammu/src/gammu.c b/gammu/src/gammu.c index 7c0d8e4a5..761327ba1 100644 --- a/gammu/src/gammu.c +++ b/gammu/src/gammu.c @@ -1865,10 +1865,11 @@ StateMachine_GetNetworkInfo(StateMachineObject *self, PyObject *args, PyObject * /* Detect if NetworkName is Unicode or ASCII string. * Unicode strings in Gammu use 2-byte encoding (little-endian). * ASCII strings from dummy backend are regular C strings. - * Heuristic: if second byte is 0 (empty string or Unicode pattern), use Unicode path. - * Otherwise, treat as ASCII for backward compatibility with dummy backend. + * Heuristic: if second byte is 0 and first byte is non-zero, it's Unicode. + * If both bytes are 0, it's empty (compatible with both). + * Otherwise, treat as ASCII for backward compatibility. */ - if (netinfo.NetworkName[0] == 0 || netinfo.NetworkName[1] == 0) { + if (netinfo.NetworkName[0] == 0 || (netinfo.NetworkName[0] != 0 && netinfo.NetworkName[1] == 0)) { /* Unicode string or empty */ network_name = UnicodeStringToPython(netinfo.NetworkName); } else { From 6f790700ba7fcdca77c75e36a30a6d6671267c72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Wed, 4 Feb 2026 16:38:11 +0100 Subject: [PATCH 17/18] Revert "Add Unicode/ASCII detection for NetworkName compatibility" This reverts commit f2f9087b0bf79553902dfce91a9563eee10bed5a. --- gammu/src/gammu.c | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-) diff --git a/gammu/src/gammu.c b/gammu/src/gammu.c index 761327ba1..c7f35d7a3 100644 --- a/gammu/src/gammu.c +++ b/gammu/src/gammu.c @@ -1862,21 +1862,7 @@ StateMachine_GetNetworkInfo(StateMachineObject *self, PyObject *args, PyObject * case GSM_NetworkStatusUnknown: packet_state = "NetworkStatusUnknown"; break; } - /* Detect if NetworkName is Unicode or ASCII string. - * Unicode strings in Gammu use 2-byte encoding (little-endian). - * ASCII strings from dummy backend are regular C strings. - * Heuristic: if second byte is 0 and first byte is non-zero, it's Unicode. - * If both bytes are 0, it's empty (compatible with both). - * Otherwise, treat as ASCII for backward compatibility. - */ - if (netinfo.NetworkName[0] == 0 || (netinfo.NetworkName[0] != 0 && netinfo.NetworkName[1] == 0)) { - /* Unicode string or empty */ - network_name = UnicodeStringToPython(netinfo.NetworkName); - } else { - /* ASCII string (e.g., from dummy backend) */ - network_name = LocaleStringToPython((char *)netinfo.NetworkName); - } - + network_name = UnicodeStringToPython(netinfo.NetworkName); if (network_name == NULL) return NULL; From a360a6b0fb5feda16075df239ec130403688fe68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Wed, 4 Feb 2026 16:38:50 +0100 Subject: [PATCH 18/18] Fix test expectation --- test/test_asyncworker.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_asyncworker.py b/test/test_asyncworker.py index 8768cce1a..32243ce02 100644 --- a/test/test_asyncworker.py +++ b/test/test_asyncworker.py @@ -35,7 +35,7 @@ "GPRS": "Attached", "LAC": "B00B", "NetworkCode": "999 99", - "NetworkName": "", + "NetworkName": "GammuT3l", "PacketCID": "DEAD", "PacketLAC": "BEEF", "PacketState": "HomeNetwork",