1*4882a593Smuzhiyun#!/usr/bin/env python 2*4882a593Smuzhiyun# Copyright 2009 Simon Arlott 3*4882a593Smuzhiyun# 4*4882a593Smuzhiyun# This program is free software; you can redistribute it and/or modify it 5*4882a593Smuzhiyun# under the terms of the GNU General Public License as published by the Free 6*4882a593Smuzhiyun# Software Foundation; either version 2 of the License, or (at your option) 7*4882a593Smuzhiyun# any later version. 8*4882a593Smuzhiyun# 9*4882a593Smuzhiyun# This program is distributed in the hope that it will be useful, but WITHOUT 10*4882a593Smuzhiyun# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11*4882a593Smuzhiyun# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 12*4882a593Smuzhiyun# more details. 13*4882a593Smuzhiyun# 14*4882a593Smuzhiyun# You should have received a copy of the GNU General Public License along with 15*4882a593Smuzhiyun# this program; if not, write to the Free Software Foundation, Inc., 59 16*4882a593Smuzhiyun# Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17*4882a593Smuzhiyun# 18*4882a593Smuzhiyun# Usage: cxacru-cf.py < cxacru-cf.bin 19*4882a593Smuzhiyun# Output: values string suitable for the sysfs adsl_config attribute 20*4882a593Smuzhiyun# 21*4882a593Smuzhiyun# Warning: cxacru-cf.bin with MD5 hash cdbac2689969d5ed5d4850f117702110 22*4882a593Smuzhiyun# contains mis-aligned values which will stop the modem from being able 23*4882a593Smuzhiyun# to make a connection. If the first and last two bytes are removed then 24*4882a593Smuzhiyun# the values become valid, but the modulation will be forced to ANSI 25*4882a593Smuzhiyun# T1.413 only which may not be appropriate. 26*4882a593Smuzhiyun# 27*4882a593Smuzhiyun# The original binary format is a packed list of le32 values. 28*4882a593Smuzhiyun 29*4882a593Smuzhiyunimport sys 30*4882a593Smuzhiyunimport struct 31*4882a593Smuzhiyun 32*4882a593Smuzhiyuni = 0 33*4882a593Smuzhiyunwhile True: 34*4882a593Smuzhiyun buf = sys.stdin.read(4) 35*4882a593Smuzhiyun 36*4882a593Smuzhiyun if len(buf) == 0: 37*4882a593Smuzhiyun break 38*4882a593Smuzhiyun elif len(buf) != 4: 39*4882a593Smuzhiyun sys.stdout.write("\n") 40*4882a593Smuzhiyun sys.stderr.write("Error: read {0} not 4 bytes\n".format(len(buf))) 41*4882a593Smuzhiyun sys.exit(1) 42*4882a593Smuzhiyun 43*4882a593Smuzhiyun if i > 0: 44*4882a593Smuzhiyun sys.stdout.write(" ") 45*4882a593Smuzhiyun sys.stdout.write("{0:x}={1}".format(i, struct.unpack("<I", buf)[0])) 46*4882a593Smuzhiyun i += 1 47*4882a593Smuzhiyun 48*4882a593Smuzhiyunsys.stdout.write("\n") 49