Skip to content

Commit c0f932e

Browse files
committed
Implement setting country in wpa_supplicant.conf
1 parent 1ae9b21 commit c0f932e

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

netconnectd/protocol.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,8 @@ class CountryList(Message):
150150

151151
class SetCountry(Message):
152152
__cmd__ = "set_country"
153+
__mandatory_params__ = {"country_code"}
154+
153155

154156

155157
class Response(object):

netconnectd/server.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -776,8 +776,25 @@ def on_country_list_message(self, message):
776776
"countries": self.country_list,}
777777

778778
def on_set_country_message(self, message):
779-
# Todo - set country
780-
pass
779+
self.logger.info("Setting country to {}.".format(message.country_code))
780+
try:
781+
with open("/etc/wpa_supplicant/wpa_supplicant.conf") as wpa_s_c:
782+
content = ""
783+
skip = False
784+
for line in wpa_s_c:
785+
if not line.strip():
786+
skip = False
787+
elif line.strip().startswith("country="):
788+
skip = True
789+
if not skip:
790+
content += line
791+
content += "country={}\n".format(message.country_code)
792+
with open("/etc/wpa_supplicant/wpa_supplicant.conf", "w") as wpa_s_c:
793+
wpa_s_c.write(content)
794+
return True, "country changed"
795+
except Exception as e:
796+
self.logger.warn("Unable to set country: " + e)
797+
return False, "error on changing country"
781798

782799
@property
783800
def wifi_connection_ssid(self):

0 commit comments

Comments
 (0)