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
|
|
|
|
2018-02-03 21:25:26 +00:00
|
|
|
"""Checks for the latest FULL or OTA updates for specified PRD number."""
|
|
|
|
|
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
|
2018-02-03 20:24:36 +00:00
|
|
|
|
2018-02-10 02:30:10 +00:00
|
|
|
from tcllib import argparser
|
2018-02-07 00:49:44 +00:00
|
|
|
from tcllib.devices import Device
|
2018-02-10 02:30:10 +00:00
|
|
|
from tcllib.requests import RequestRunner, CheckRequest, DownloadRequest, \
|
|
|
|
ChecksumRequest, EncryptHeaderRequest, ServerSelector, \
|
|
|
|
write_info_if_dumps_found
|
2018-02-05 12:20:15 +00:00
|
|
|
from tcllib.xmltools import pretty_xml
|
2017-08-05 15:25:42 +01:00
|
|
|
|
2018-02-03 20:24:36 +00:00
|
|
|
|
2018-01-30 17:31:05 +00:00
|
|
|
dpdesc = """
|
2017-12-26 23:35:00 +00:00
|
|
|
Checks for the latest FULL updates for the specified PRD number or for an OTA from the
|
|
|
|
version specified as fvver.
|
|
|
|
"""
|
2018-02-10 02:30:10 +00:00
|
|
|
dp = argparser.DefaultParser(__file__, dpdesc)
|
2017-12-26 23:35:00 +00:00
|
|
|
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)
|
2018-02-03 20:24:36 +00:00
|
|
|
dp.add_argument("-m", "--mode", help="force type of update to check for", default="auto", type=str, choices=["full", "ota"])
|
2017-12-27 00:34:20 +00:00
|
|
|
dp.add_argument("-t", "--type", help="force type of check to run", default="auto", type=str, choices=["desktop", "mobile"])
|
2018-01-30 17:31:05 +00:00
|
|
|
dp.add_argument("--rawmode", help="override --mode with raw value (2=OTA, 4=FULL)", metavar="MODE")
|
|
|
|
dp.add_argument("--rawcltp", help="override --type with raw value (10=MOBILE, 2010=DESKTOP)", metavar="CLTP")
|
2017-10-10 20:25:38 +01:00
|
|
|
args = dp.parse_args(sys.argv[1:])
|
|
|
|
|
2018-02-07 00:49:44 +00:00
|
|
|
dev = Device(args.prd[0], args.fvver)
|
|
|
|
dev.imei = "3531510"
|
2018-02-03 20:24:36 +00:00
|
|
|
|
2017-12-27 00:34:20 +00:00
|
|
|
def sel_mode(txtmode, autoval, rawval):
|
2018-02-03 21:25:26 +00:00
|
|
|
"""Handle custom mode."""
|
2017-12-27 00:34:20 +00:00
|
|
|
if rawval:
|
2018-02-07 00:49:44 +00:00
|
|
|
return rawval
|
2017-12-26 23:35:00 +00:00
|
|
|
if txtmode == "auto":
|
|
|
|
return autoval
|
|
|
|
elif txtmode == "ota":
|
2018-02-07 00:49:44 +00:00
|
|
|
return dev.MODE_STATES["OTA"]
|
|
|
|
return dev.MODE_STATES["FULL"]
|
2018-02-03 20:24:36 +00:00
|
|
|
|
2017-12-27 00:34:20 +00:00
|
|
|
def sel_cltp(txtmode, autoval, rawval):
|
2018-02-03 21:25:26 +00:00
|
|
|
"""Handle custom CLTP."""
|
2017-12-27 00:34:20 +00:00
|
|
|
if rawval:
|
2018-02-07 00:49:44 +00:00
|
|
|
return rawval
|
2017-12-26 23:35:00 +00:00
|
|
|
if txtmode == "auto":
|
|
|
|
return autoval
|
|
|
|
elif txtmode == "desktop":
|
2018-02-07 00:49:44 +00:00
|
|
|
return dev.CLTP_STATES["DESKTOP"]
|
|
|
|
return dev.CLTP_STATES["MOBILE"]
|
2018-02-03 20:24:36 +00:00
|
|
|
|
2018-01-04 21:23:03 +00:00
|
|
|
if args.imei:
|
|
|
|
print("Use specified IMEI: {}".format(args.imei))
|
2018-02-07 00:49:44 +00:00
|
|
|
dev.imei = args.imei
|
2018-01-04 21:23:03 +00:00
|
|
|
|
2017-12-26 23:35:00 +00:00
|
|
|
if args.fvver == "AAA000":
|
2018-02-07 00:49:44 +00:00
|
|
|
dev.mode = sel_mode(args.mode, dev.MODE_STATES["FULL"], args.rawmode)
|
|
|
|
dev.cltp = sel_cltp(args.type, dev.CLTP_STATES["DESKTOP"], args.rawcltp)
|
2017-12-26 23:35:00 +00:00
|
|
|
else:
|
2018-02-07 00:49:44 +00:00
|
|
|
dev.mode = sel_mode(args.mode, dev.MODE_STATES["OTA"], args.rawmode)
|
|
|
|
dev.cltp = sel_cltp(args.type, dev.CLTP_STATES["MOBILE"], args.rawcltp)
|
2017-09-01 12:43:10 +01:00
|
|
|
|
2018-02-07 00:49:44 +00:00
|
|
|
print("Mode: {}".format(dev.mode))
|
|
|
|
print("CLTP: {}".format(dev.cltp))
|
2018-01-04 21:23:03 +00:00
|
|
|
|
2018-02-10 01:38:39 +00:00
|
|
|
runner = RequestRunner(ServerSelector())
|
|
|
|
|
|
|
|
# Check for update
|
|
|
|
chk = CheckRequest(dev)
|
|
|
|
runner.run(chk)
|
|
|
|
if not chk.success:
|
|
|
|
print("{}".format(chk.error))
|
|
|
|
sys.exit(2)
|
|
|
|
chkres = chk.get_result()
|
|
|
|
print(chkres.pretty_xml())
|
|
|
|
|
|
|
|
# Request download
|
|
|
|
dlr = DownloadRequest(dev, chkres.tvver, chkres.fw_id)
|
|
|
|
runner.run(dlr)
|
|
|
|
if not dlr.success:
|
|
|
|
print("{}".format(dlr.error))
|
|
|
|
sys.exit(3)
|
|
|
|
dlrres = dlr.get_result()
|
|
|
|
print(dlrres.pretty_xml())
|
|
|
|
|
|
|
|
if dlrres.encslaves:
|
2018-02-10 02:30:10 +00:00
|
|
|
encrunner = RequestRunner(ServerSelector(dlrres.encslaves), https=False)
|
2018-02-10 02:12:24 +00:00
|
|
|
cks = ChecksumRequest(dlrres.fileurl, dlrres.fileurl)
|
2018-02-10 02:30:10 +00:00
|
|
|
encrunner.run(cks)
|
2018-02-10 02:12:24 +00:00
|
|
|
if not cks.success:
|
|
|
|
print("{}".format(cks.error))
|
|
|
|
sys.exit(4)
|
|
|
|
cksres = cks.get_result()
|
|
|
|
print(cksres.pretty_xml())
|
|
|
|
|
|
|
|
for s in dlrres.slaves:
|
|
|
|
print("http://{}{}".format(s, dlrres.fileurl))
|
|
|
|
|
|
|
|
for s in dlrres.s3_slaves:
|
|
|
|
print("http://{}{}".format(s, dlrres.s3_fileurl))
|
2018-01-11 23:31:39 +00:00
|
|
|
|
2018-02-07 00:49:44 +00:00
|
|
|
if dev.mode == dev.MODE_STATES["FULL"]:
|
2018-02-10 02:30:10 +00:00
|
|
|
hdr = EncryptHeaderRequest(dlrres.fileurl)
|
|
|
|
encrunner.run(hdr)
|
|
|
|
if not hdr.success:
|
|
|
|
print("{}".format(hdr.error))
|
|
|
|
sys.exit(5)
|
|
|
|
hdrres = hdr.get_result()
|
|
|
|
headname = "header_{}.bin".format(chkres.tvver)
|
2017-11-03 05:00:49 +00:00
|
|
|
headdir = "headers"
|
|
|
|
if not os.path.exists(headdir):
|
|
|
|
os.makedirs(headdir)
|
2018-02-10 02:30:10 +00:00
|
|
|
if len(hdrres.rawdata) == 4194320:
|
2018-01-12 01:36:51 +00:00
|
|
|
# TODO: Check sha1sum
|
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:
|
2018-02-10 02:30:10 +00:00
|
|
|
f.write(hdrres.rawdata)
|
2017-09-01 13:07:06 +01:00
|
|
|
else:
|
2018-02-10 02:30:10 +00:00
|
|
|
print("Header length invalid ({}).".format(len(hdrres.rawdata)))
|
2017-11-12 21:19:04 +00:00
|
|
|
|
2018-02-10 02:30:10 +00:00
|
|
|
write_info_if_dumps_found()
|