From e7d6d472c21aa80c28be01c0d6dcbfd250d57a25 Mon Sep 17 00:00:00 2001 From: nima Date: Mon, 30 Jun 2008 12:08:58 +0000 Subject: First commit to SVN. git-svn-id: svn://svn.autonomy.net.au/python-dmidecode@1 abc39116-655e-4be6-ad55-d661dc543056 --- ownership.c | 212 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 212 insertions(+) create mode 100644 ownership.c (limited to 'ownership.c') diff --git a/ownership.c b/ownership.c new file mode 100644 index 0000000..29b9850 --- /dev/null +++ b/ownership.c @@ -0,0 +1,212 @@ +/* + * Compaq Ownership Tag + * + * (C) 2003-2005 Jean Delvare + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * For the avoidance of doubt the "preferred form" of this code is one which + * is in an open unpatent encumbered format. Where cryptographic key signing + * forms part of the process of creating an executable the information + * including keys needed to generate an equivalently functional executable + * are deemed to be part of the source code. + * + * References: + * - Compaq "Technical Reference Guide for Compaq Deskpro 4000 and 6000" + * First Edition + * http://h18000.www1.hp.com/support/techpubs/technical_reference_guides/113a1097.html + */ + +#include +#include +#include +#include +#include + +#include "version.h" +#include "config.h" +#include "types.h" +#include "util.h" + +/* Options are global */ +struct opt +{ + const char* devmem; + unsigned int flags; +}; +static struct opt opt; + +#define FLAG_VERSION (1<<0) +#define FLAG_HELP (1<<1) + +static void ownership(u32 base, const char *pname, const char *devmem) +{ + u8 *buf; + int i; + + /* read the ownership tag */ + if((buf=mem_chunk(base, 0x51, devmem))==NULL) + { + perror(pname); + return; + } + + /* chop the trailing garbage */ + i=0x4f; + while(i>=0 && (buf[i]==0x20 || buf[i]==0x00)) + i--; + buf[i+1]='\0'; + + /* filter and print */ + if(i>=0) + { + for(; i>=0; i--) + { + if(buf[i]<32 || (buf[i]>=127 && buf[i]<160)) + buf[i]='?'; + } + printf("%s\n", (char *)buf); + } + + free(buf); +} + +static u32 decode(const u8 *p) +{ + int i; + + /* integrity checking (lack of checksum) */ + for(i=0; i='A' && p[6+i*10]<='Z') + || !(p[7+i*10]>='A' && p[7+i*10]<='Z') + || !(p[8+i*10]>='A' && p[8+i*10]<='Z')) + { + printf("\t Abnormal Entry! Please report. [%02x %02x %02x %02x]\n", + p[5+i*10], p[6+i*10], p[7+i*10], p[8+i*10]); + return 0; + } + } + + /* search for the right entry */ + for(i=0; i