mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
esp_prov : Support new JSON format of version string while maintaining backward compatibility
Other changes: * Version check only happens if command line argument is specified * Minor bugfix in processing apply_config response
This commit is contained in:
parent
f90d3f6d93
commit
a92ace034f
@ -20,6 +20,7 @@ import argparse
|
|||||||
import time
|
import time
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
import json
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import security
|
import security
|
||||||
@ -81,13 +82,26 @@ def get_transport(sel_transport, softap_endpoint=None, ble_devname=None):
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
def version_match(tp, protover):
|
def version_match(tp, protover, verbose=False):
|
||||||
try:
|
try:
|
||||||
response = tp.send_data('proto-ver', protover)
|
response = tp.send_data('proto-ver', protover)
|
||||||
if response != protover:
|
|
||||||
return False
|
if verbose:
|
||||||
|
print("proto-ver response : ", response)
|
||||||
|
|
||||||
|
# First assume this to be a simple version string
|
||||||
|
if response.lower() == protover.lower():
|
||||||
return True
|
return True
|
||||||
except RuntimeError as e:
|
|
||||||
|
# Else interpret this as JSON structure containing
|
||||||
|
# information with versions and capabilities of both
|
||||||
|
# provisioning service and application
|
||||||
|
info = json.loads(response)
|
||||||
|
if info['prov']['ver'].lower() == protover.lower():
|
||||||
|
return True
|
||||||
|
|
||||||
|
return False
|
||||||
|
except Exception as e:
|
||||||
on_except(e)
|
on_except(e)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@ -132,7 +146,7 @@ def apply_wifi_config(tp, sec):
|
|||||||
try:
|
try:
|
||||||
message = prov.config_apply_config_request(sec)
|
message = prov.config_apply_config_request(sec)
|
||||||
response = tp.send_data('prov-config', message)
|
response = tp.send_data('prov-config', message)
|
||||||
return (prov.config_set_config_response(sec, response) == 0)
|
return (prov.config_apply_config_response(sec, response) == 0)
|
||||||
except RuntimeError as e:
|
except RuntimeError as e:
|
||||||
on_except(e)
|
on_except(e)
|
||||||
return None
|
return None
|
||||||
@ -159,7 +173,7 @@ if __name__ == '__main__':
|
|||||||
parser.add_argument("--sec_ver", dest='secver', type=int,
|
parser.add_argument("--sec_ver", dest='secver', type=int,
|
||||||
help="Security scheme version", default=1)
|
help="Security scheme version", default=1)
|
||||||
parser.add_argument("--proto_ver", dest='protover', type=str,
|
parser.add_argument("--proto_ver", dest='protover', type=str,
|
||||||
help="Protocol version", default='V0.1')
|
help="Protocol version", default='')
|
||||||
parser.add_argument("--pop", dest='pop', type=str,
|
parser.add_argument("--pop", dest='pop', type=str,
|
||||||
help="Proof of possession", default='')
|
help="Proof of possession", default='')
|
||||||
|
|
||||||
@ -182,6 +196,7 @@ if __name__ == '__main__':
|
|||||||
parser.add_argument("-v","--verbose", help="increase output verbosity", action="store_true")
|
parser.add_argument("-v","--verbose", help="increase output verbosity", action="store_true")
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
if args.protover != '':
|
||||||
print("==== Esp_Prov Version: " + args.protover + " ====")
|
print("==== Esp_Prov Version: " + args.protover + " ====")
|
||||||
|
|
||||||
obj_security = get_security(args.secver, args.pop, args.verbose)
|
obj_security = get_security(args.secver, args.pop, args.verbose)
|
||||||
@ -194,8 +209,9 @@ if __name__ == '__main__':
|
|||||||
print("---- Invalid provisioning mode ----")
|
print("---- Invalid provisioning mode ----")
|
||||||
exit(2)
|
exit(2)
|
||||||
|
|
||||||
|
if args.protover != '':
|
||||||
print("\n==== Verifying protocol version ====")
|
print("\n==== Verifying protocol version ====")
|
||||||
if not version_match(obj_transport, args.protover):
|
if not version_match(obj_transport, args.protover, args.verbose):
|
||||||
print("---- Error in protocol version matching ----")
|
print("---- Error in protocol version matching ----")
|
||||||
exit(3)
|
exit(3)
|
||||||
print("==== Verified protocol version successfully ====")
|
print("==== Verified protocol version successfully ====")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user