2017-08-15 14:20:26 +01:00
|
|
|
#!/usr/bin/env python3
|
2017-08-18 23:49:12 +01:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
2017-10-05 23:25:45 +01:00
|
|
|
# pylint: disable=C0111,C0326,C0103
|
2017-08-15 14:20:26 +01:00
|
|
|
|
2017-11-03 05:00:49 +00:00
|
|
|
import os
|
2017-09-01 12:59:12 +01:00
|
|
|
import random
|
2017-08-08 05:24:16 +01:00
|
|
|
import sys
|
2017-10-05 23:25:45 +01:00
|
|
|
import tcllib
|
2017-08-05 15:25:42 +01:00
|
|
|
|
2017-09-01 12:43:10 +01:00
|
|
|
fc = tcllib.FotaCheck()
|
2017-09-23 22:31:32 +01:00
|
|
|
fc.serid = "3531510"
|
|
|
|
#fc.osvs = "7.1.1"
|
|
|
|
|
2017-10-10 20:25:38 +01:00
|
|
|
dp = tcllib.DefaultParser(__file__)
|
2017-12-26 23:35:00 +00:00
|
|
|
dp.description = """
|
|
|
|
Checks for the latest FULL updates for the specified PRD number or for an OTA from the
|
|
|
|
version specified as fvver.
|
|
|
|
"""
|
|
|
|
dp.add_argument("prd", nargs=1, help="CU Reference #, e.g. PRD-63117-011")
|
2017-12-26 23:48:01 +00:00
|
|
|
dp.add_argument("fvver", nargs="?", help="Firmware version to check for OTA updates, e.g. AAM481 (omit to run FULL check)", default="AAA000")
|
2018-01-04 21:23:03 +00:00
|
|
|
dp.add_argument("-i", "--imei", help="use specified IMEI instead of default", type=str)
|
2017-12-27 00:34:20 +00:00
|
|
|
dp.add_argument("-m", "--mode", help="force type of update to check for", default="auto", type=str ,choices=["full", "ota"])
|
|
|
|
dp.add_argument("-t", "--type", help="force type of check to run", default="auto", type=str, choices=["desktop", "mobile"])
|
|
|
|
dp.add_argument("--rawmode", help="override --mode with raw value (2=OTA, 4=FULL)")
|
|
|
|
dp.add_argument("--rawcltp", help="override --type with raw value (10=MOBILE, 2010=DESKTOP)")
|
2017-10-10 20:25:38 +01:00
|
|
|
args = dp.parse_args(sys.argv[1:])
|
|
|
|
|
2017-12-27 00:34:20 +00:00
|
|
|
def sel_mode(txtmode, autoval, rawval):
|
|
|
|
if rawval:
|
|
|
|
enum = tcllib.default_enum("MODE", {"RAW": rawval})
|
|
|
|
return enum.RAW
|
2017-12-26 23:35:00 +00:00
|
|
|
if txtmode == "auto":
|
|
|
|
return autoval
|
|
|
|
elif txtmode == "ota":
|
|
|
|
return fc.MODE.OTA
|
|
|
|
return fc.MODE.FULL
|
|
|
|
|
2017-12-27 00:34:20 +00:00
|
|
|
def sel_cltp(txtmode, autoval, rawval):
|
|
|
|
if rawval:
|
|
|
|
enum = tcllib.default_enum("CLTP", {"RAW": rawval})
|
|
|
|
return enum.RAW
|
2017-12-26 23:35:00 +00:00
|
|
|
if txtmode == "auto":
|
|
|
|
return autoval
|
|
|
|
elif txtmode == "desktop":
|
|
|
|
return fc.CLTP.DESKTOP
|
|
|
|
return fc.CLTP.MOBILE
|
|
|
|
|
2018-01-04 21:23:03 +00:00
|
|
|
if args.imei:
|
|
|
|
print("Use specified IMEI: {}".format(args.imei))
|
|
|
|
fc.serid = args.imei
|
|
|
|
|
2017-12-26 23:35:00 +00:00
|
|
|
fc.curef = args.prd[0]
|
|
|
|
fc.fv = args.fvver
|
|
|
|
if args.fvver == "AAA000":
|
2017-12-27 00:34:20 +00:00
|
|
|
fc.mode = sel_mode(args.mode, fc.MODE.FULL, args.rawmode)
|
|
|
|
fc.cltp = sel_cltp(args.type, fc.CLTP.DESKTOP, args.rawcltp)
|
2017-12-26 23:35:00 +00:00
|
|
|
else:
|
2017-12-27 00:34:20 +00:00
|
|
|
fc.mode = sel_mode(args.mode, fc.MODE.OTA, args.rawmode)
|
|
|
|
fc.cltp = sel_cltp(args.type, fc.CLTP.MOBILE, args.rawcltp)
|
2017-09-01 12:43:10 +01:00
|
|
|
|
2018-01-04 21:23:03 +00:00
|
|
|
print("Mode: {}".format(fc.mode.value))
|
|
|
|
print("CLTP: {}".format(fc.cltp.value))
|
|
|
|
|
2017-09-01 12:43:10 +01:00
|
|
|
check_xml = fc.do_check()
|
2017-09-01 12:59:12 +01:00
|
|
|
print(fc.pretty_xml(check_xml))
|
2017-09-01 12:43:10 +01:00
|
|
|
curef, fv, tv, fw_id, fileid, fn, fsize, fhash = fc.parse_check(check_xml)
|
|
|
|
|
|
|
|
req_xml = fc.do_request(curef, fv, tv, fw_id)
|
|
|
|
print(fc.pretty_xml(req_xml))
|
2018-01-11 23:31:39 +00:00
|
|
|
fileid, fileurl, slaves, encslaves, s3_fileurl, s3_slaves = fc.parse_request(req_xml)
|
2017-09-01 12:43:10 +01:00
|
|
|
|
2018-01-11 23:40:42 +00:00
|
|
|
chksum_xml = fc.do_checksum(random.choice(encslaves), fileurl, fileurl)
|
|
|
|
print(fc.pretty_xml(chksum_xml))
|
|
|
|
|
2017-09-01 12:43:10 +01:00
|
|
|
for s in slaves:
|
|
|
|
print("http://{}{}".format(s, fileurl))
|
|
|
|
|
2018-01-11 23:31:39 +00:00
|
|
|
for s in s3_slaves:
|
|
|
|
print("http://{}{}".format(s, s3_fileurl))
|
|
|
|
|
2017-10-15 01:02:24 +01:00
|
|
|
if fc.mode == fc.MODE.FULL:
|
2017-09-01 13:07:06 +01:00
|
|
|
header = fc.do_encrypt_header(random.choice(encslaves), fileurl)
|
2017-11-03 05:00:49 +00:00
|
|
|
headname = "header_{}.bin".format(tv)
|
|
|
|
headdir = "headers"
|
|
|
|
if not os.path.exists(headdir):
|
|
|
|
os.makedirs(headdir)
|
2017-09-01 13:07:06 +01:00
|
|
|
if len(header) == 4194320:
|
2017-11-03 05:00:49 +00:00
|
|
|
print("Header length check passed. Writing to {}.".format(headname))
|
|
|
|
with open(os.path.join(headdir, headname), "wb") as f:
|
2017-09-01 13:07:06 +01:00
|
|
|
f.write(header)
|
|
|
|
else:
|
|
|
|
print("Header length invalid ({}).".format(len(header)))
|
2017-11-12 21:19:04 +00:00
|
|
|
|
|
|
|
tcllib.FotaCheck.write_info_if_dumps_found()
|