18c2ecf20Sopenharmony_ci#!/usr/bin/env python
28c2ecf20Sopenharmony_ci# Copyright 2009 Simon Arlott
38c2ecf20Sopenharmony_ci#
48c2ecf20Sopenharmony_ci# This program is free software; you can redistribute it and/or modify it
58c2ecf20Sopenharmony_ci# under the terms of the GNU General Public License as published by the Free
68c2ecf20Sopenharmony_ci# Software Foundation; either version 2 of the License, or (at your option)
78c2ecf20Sopenharmony_ci# any later version.
88c2ecf20Sopenharmony_ci#
98c2ecf20Sopenharmony_ci# This program is distributed in the hope that it will be useful, but WITHOUT
108c2ecf20Sopenharmony_ci# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
118c2ecf20Sopenharmony_ci# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
128c2ecf20Sopenharmony_ci# more details.
138c2ecf20Sopenharmony_ci#
148c2ecf20Sopenharmony_ci# You should have received a copy of the GNU General Public License along with
158c2ecf20Sopenharmony_ci# this program; if not, write to the Free Software Foundation, Inc., 59
168c2ecf20Sopenharmony_ci# Temple Place - Suite 330, Boston, MA  02111-1307, USA.
178c2ecf20Sopenharmony_ci#
188c2ecf20Sopenharmony_ci# Usage: cxacru-cf.py < cxacru-cf.bin
198c2ecf20Sopenharmony_ci# Output: values string suitable for the sysfs adsl_config attribute
208c2ecf20Sopenharmony_ci#
218c2ecf20Sopenharmony_ci# Warning: cxacru-cf.bin with MD5 hash cdbac2689969d5ed5d4850f117702110
228c2ecf20Sopenharmony_ci# contains mis-aligned values which will stop the modem from being able
238c2ecf20Sopenharmony_ci# to make a connection. If the first and last two bytes are removed then
248c2ecf20Sopenharmony_ci# the values become valid, but the modulation will be forced to ANSI
258c2ecf20Sopenharmony_ci# T1.413 only which may not be appropriate.
268c2ecf20Sopenharmony_ci#
278c2ecf20Sopenharmony_ci# The original binary format is a packed list of le32 values.
288c2ecf20Sopenharmony_ci
298c2ecf20Sopenharmony_ciimport sys
308c2ecf20Sopenharmony_ciimport struct
318c2ecf20Sopenharmony_ci
328c2ecf20Sopenharmony_cii = 0
338c2ecf20Sopenharmony_ciwhile True:
348c2ecf20Sopenharmony_ci	buf = sys.stdin.read(4)
358c2ecf20Sopenharmony_ci
368c2ecf20Sopenharmony_ci	if len(buf) == 0:
378c2ecf20Sopenharmony_ci		break
388c2ecf20Sopenharmony_ci	elif len(buf) != 4:
398c2ecf20Sopenharmony_ci		sys.stdout.write("\n")
408c2ecf20Sopenharmony_ci		sys.stderr.write("Error: read {0} not 4 bytes\n".format(len(buf)))
418c2ecf20Sopenharmony_ci		sys.exit(1)
428c2ecf20Sopenharmony_ci
438c2ecf20Sopenharmony_ci	if i > 0:
448c2ecf20Sopenharmony_ci		sys.stdout.write(" ")
458c2ecf20Sopenharmony_ci	sys.stdout.write("{0:x}={1}".format(i, struct.unpack("<I", buf)[0]))
468c2ecf20Sopenharmony_ci	i += 1
478c2ecf20Sopenharmony_ci
488c2ecf20Sopenharmony_cisys.stdout.write("\n")
49