wifi_provisioning: added wifi-ctrl reprov endpoint

This commit is contained in:
harshal.patil
2022-10-20 15:56:00 +05:30
parent dacf44dd1d
commit b7de443aaa
9 changed files with 341 additions and 17 deletions
+20 -2
View File
@@ -290,7 +290,7 @@ async def wait_wifi_connected(tp, sec):
return False
async def reset_wifi(sel_transport, tp, sec):
async def reset_wifi(tp, sec):
try:
message = prov.ctrl_reset_request(sec)
response = await tp.send_data('prov-ctrl', message)
@@ -301,6 +301,17 @@ async def reset_wifi(sel_transport, tp, sec):
return None
async def reprov_wifi(tp, sec):
try:
message = prov.ctrl_reprov_request(sec)
response = await tp.send_data('prov-ctrl', message)
prov.ctrl_reprov_response(sec, response)
except RuntimeError as e:
on_except(e)
return None
def desc_format(*args):
desc = ''
for arg in args:
@@ -385,6 +396,8 @@ async def main():
parser.add_argument('--reset', help='Reset WiFi', action='store_true')
parser.add_argument('--reprov', help='Reprovision WiFi', action='store_true')
parser.add_argument('-v','--verbose', help='Increase output verbosity', action='store_true')
args = parser.parse_args()
@@ -447,7 +460,12 @@ async def main():
if args.reset:
print('==== Reseting WiFi====')
await reset_wifi(args.mode.lower(), obj_transport, obj_security)
await reset_wifi(obj_transport, obj_security)
sys.exit()
if args.reprov:
print('==== Reprovisioning WiFi====')
await reprov_wifi(obj_transport, obj_security)
sys.exit()
if args.custom_data != '':
+19
View File
@@ -30,3 +30,22 @@ def ctrl_reset_response(security_ctx, response_data):
print_verbose(security_ctx, f'CtrlReset status: 0x{str(resp.status)}')
if resp.status != 0:
raise RuntimeError
def ctrl_reprov_request(security_ctx):
# Form protobuf request packet for CtrlReprov command
cmd = proto.wifi_ctrl_pb2.WiFiCtrlPayload()
cmd.msg = proto.wifi_ctrl_pb2.TypeCmdCtrlReprov
enc_cmd = security_ctx.encrypt_data(cmd.SerializeToString())
print_verbose(security_ctx, f'Client -> Device (Encrypted CmdCtrlReset): 0x{enc_cmd.hex()}')
return enc_cmd.decode('latin-1')
def ctrl_reprov_response(security_ctx, response_data):
# Interpret protobuf response packet from CtrlReprov command
dec_resp = security_ctx.decrypt_data(str_to_bytes(response_data))
resp = proto.wifi_ctrl_pb2.WiFiCtrlPayload()
resp.ParseFromString(dec_resp)
print_verbose(security_ctx, f'CtrlReset status: 0x{str(resp.status)}')
if resp.status != 0:
raise RuntimeError