162306a36Sopenharmony_ci#!/usr/bin/env python
262306a36Sopenharmony_ci# Copyright 2009 Simon Arlott
362306a36Sopenharmony_ci#
462306a36Sopenharmony_ci# This program is free software; you can redistribute it and/or modify it
562306a36Sopenharmony_ci# under the terms of the GNU General Public License as published by the Free
662306a36Sopenharmony_ci# Software Foundation; either version 2 of the License, or (at your option)
762306a36Sopenharmony_ci# any later version.
862306a36Sopenharmony_ci#
962306a36Sopenharmony_ci# This program is distributed in the hope that it will be useful, but WITHOUT
1062306a36Sopenharmony_ci# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1162306a36Sopenharmony_ci# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
1262306a36Sopenharmony_ci# more details.
1362306a36Sopenharmony_ci#
1462306a36Sopenharmony_ci# You should have received a copy of the GNU General Public License along with
1562306a36Sopenharmony_ci# this program; if not, write to the Free Software Foundation, Inc., 59
1662306a36Sopenharmony_ci# Temple Place - Suite 330, Boston, MA  02111-1307, USA.
1762306a36Sopenharmony_ci#
1862306a36Sopenharmony_ci# Usage: cxacru-cf.py < cxacru-cf.bin
1962306a36Sopenharmony_ci# Output: values string suitable for the sysfs adsl_config attribute
2062306a36Sopenharmony_ci#
2162306a36Sopenharmony_ci# Warning: cxacru-cf.bin with MD5 hash cdbac2689969d5ed5d4850f117702110
2262306a36Sopenharmony_ci# contains mis-aligned values which will stop the modem from being able
2362306a36Sopenharmony_ci# to make a connection. If the first and last two bytes are removed then
2462306a36Sopenharmony_ci# the values become valid, but the modulation will be forced to ANSI
2562306a36Sopenharmony_ci# T1.413 only which may not be appropriate.
2662306a36Sopenharmony_ci#
2762306a36Sopenharmony_ci# The original binary format is a packed list of le32 values.
2862306a36Sopenharmony_ci
2962306a36Sopenharmony_ciimport sys
3062306a36Sopenharmony_ciimport struct
3162306a36Sopenharmony_ci
3262306a36Sopenharmony_cii = 0
3362306a36Sopenharmony_ciwhile True:
3462306a36Sopenharmony_ci	buf = sys.stdin.read(4)
3562306a36Sopenharmony_ci
3662306a36Sopenharmony_ci	if len(buf) == 0:
3762306a36Sopenharmony_ci		break
3862306a36Sopenharmony_ci	elif len(buf) != 4:
3962306a36Sopenharmony_ci		sys.stdout.write("\n")
4062306a36Sopenharmony_ci		sys.stderr.write("Error: read {0} not 4 bytes\n".format(len(buf)))
4162306a36Sopenharmony_ci		sys.exit(1)
4262306a36Sopenharmony_ci
4362306a36Sopenharmony_ci	if i > 0:
4462306a36Sopenharmony_ci		sys.stdout.write(" ")
4562306a36Sopenharmony_ci	sys.stdout.write("{0:x}={1}".format(i, struct.unpack("<I", buf)[0]))
4662306a36Sopenharmony_ci	i += 1
4762306a36Sopenharmony_ci
4862306a36Sopenharmony_cisys.stdout.write("\n")
49