2010-08-18 21:49:24 +08:00
|
|
|
/*
|
|
|
|
* Written by Oron Peled <oron@actcom.co.il> and
|
|
|
|
* Alex Landau <alex.landau@xorcom.com>
|
|
|
|
* Copyright (C) 2008, Xorcom
|
|
|
|
*
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* 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., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <assert.h>
|
|
|
|
#include <getopt.h>
|
|
|
|
#include <time.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <arpa/inet.h>
|
|
|
|
#include <ctype.h>
|
2014-12-22 03:58:03 +08:00
|
|
|
#include <xtalk/debug.h>
|
2011-03-11 02:48:11 +08:00
|
|
|
#include "mpptalk.h"
|
2014-12-22 03:58:03 +08:00
|
|
|
#include "astribank.h"
|
2012-03-16 04:43:57 +08:00
|
|
|
#include "astribank_license.h"
|
2010-08-18 21:49:24 +08:00
|
|
|
|
|
|
|
static const char rcsid[] = "$Id$";
|
|
|
|
|
|
|
|
#define DBG_MASK 0x80
|
|
|
|
|
|
|
|
static char *progname;
|
|
|
|
|
|
|
|
static void usage()
|
|
|
|
{
|
|
|
|
fprintf(stderr, "Usage: %s [options...] -D {/proc/bus/usb|/dev/bus/usb}/<bus>/<dev> options\n", progname);
|
|
|
|
fprintf(stderr, "\tOptions:\n");
|
|
|
|
fprintf(stderr, "\t\t[-v] # Increase verbosity\n");
|
|
|
|
fprintf(stderr, "\t\t[-d mask] # Debug mask (0xFF for everything)\n");
|
|
|
|
fprintf(stderr, "\t\t[-w] # Write capabilities to EEPROM, otherwise read capabilities\n");
|
|
|
|
fprintf(stderr, "\t\t[-f filename] # License filename (stdin/stdout if not specified)\n\n");
|
2012-03-16 04:43:57 +08:00
|
|
|
fprintf(stderr, "\t\t[-m num] # Numeric code of License markers to generate\n");
|
|
|
|
license_markers_help("\t", stderr);
|
2010-08-18 21:49:24 +08:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
char *devpath = NULL;
|
2014-12-22 03:58:03 +08:00
|
|
|
struct astribank *astribank;
|
|
|
|
struct mpp_device *mpp;
|
2010-08-18 21:49:24 +08:00
|
|
|
struct eeprom_table eeprom_table;
|
|
|
|
struct capabilities caps;
|
|
|
|
struct capkey key;
|
2012-03-16 04:43:57 +08:00
|
|
|
const char options[] = "vd:D:wf:m:";
|
2010-08-18 21:49:24 +08:00
|
|
|
int do_write = 0;
|
2012-03-16 04:43:57 +08:00
|
|
|
unsigned int marker = LICENSE_MARKER_GENERIC;
|
2010-08-18 21:49:24 +08:00
|
|
|
FILE *file;
|
|
|
|
char *filename = NULL;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
progname = argv[0];
|
|
|
|
while (1) {
|
|
|
|
int c;
|
|
|
|
|
|
|
|
c = getopt (argc, argv, options);
|
|
|
|
if (c == -1)
|
|
|
|
break;
|
|
|
|
|
|
|
|
switch (c) {
|
|
|
|
case 'D':
|
|
|
|
devpath = optarg;
|
|
|
|
break;
|
|
|
|
case 'v':
|
|
|
|
verbose++;
|
|
|
|
break;
|
|
|
|
case 'd':
|
|
|
|
debug_mask = strtoul(optarg, NULL, 0);
|
|
|
|
break;
|
|
|
|
case 'w':
|
|
|
|
do_write = 1;
|
|
|
|
break;
|
|
|
|
case 'f':
|
|
|
|
filename = optarg;
|
|
|
|
break;
|
2012-03-16 04:43:57 +08:00
|
|
|
case 'm':
|
|
|
|
marker = strtoul(optarg, NULL, 0);
|
|
|
|
if (!license_marker_valid(marker))
|
|
|
|
usage();
|
|
|
|
break;
|
2010-08-18 21:49:24 +08:00
|
|
|
case 'h':
|
|
|
|
default:
|
|
|
|
ERR("Unknown option '%c'\n", c);
|
|
|
|
usage();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(!devpath) {
|
|
|
|
ERR("Missing device path\n");
|
|
|
|
usage();
|
|
|
|
}
|
|
|
|
DBG("Startup %s\n", devpath);
|
2014-12-22 03:58:03 +08:00
|
|
|
astribank = astribank_new(devpath);
|
|
|
|
if(!astribank) {
|
|
|
|
ERR("Failed initializing Astribank\n");
|
2010-08-18 21:49:24 +08:00
|
|
|
return 1;
|
|
|
|
}
|
2014-12-22 03:58:03 +08:00
|
|
|
mpp = astribank_mpp_open(astribank);
|
|
|
|
ret = mpp_eeprom_type(mpp);
|
|
|
|
if(ret != EEPROM_TYPE_LARGE) {
|
2010-08-18 21:49:24 +08:00
|
|
|
ERR("Cannot use this program with astribank EEPROM type %d (need %d)\n",
|
2014-12-22 03:58:03 +08:00
|
|
|
ret, EEPROM_TYPE_LARGE);
|
2010-08-18 21:49:24 +08:00
|
|
|
return 1;
|
|
|
|
}
|
2014-12-22 03:58:03 +08:00
|
|
|
ret = mpp_caps_get(mpp, &eeprom_table, &caps, &key);
|
2010-08-18 21:49:24 +08:00
|
|
|
if(ret < 0) {
|
|
|
|
ERR("Failed to get original capabilities: %d\n", ret);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
if (do_write) {
|
2012-03-20 00:57:24 +08:00
|
|
|
unsigned int used_marker;
|
2010-08-18 21:49:24 +08:00
|
|
|
/* update capabilities based on input file */
|
|
|
|
file = stdin;
|
|
|
|
if (filename) {
|
|
|
|
file = fopen(filename, "r");
|
|
|
|
if (file == NULL) {
|
|
|
|
ERR("Can't open file '%s'\n", filename);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
2012-03-16 04:43:57 +08:00
|
|
|
ret = read_from_file(&eeprom_table, &caps, &key, &used_marker, file);
|
2010-08-18 21:49:24 +08:00
|
|
|
if (ret < 0) {
|
|
|
|
ERR("Failed to read capabilities from file: %d\n", ret);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
show_capabilities(&caps, stderr);
|
2014-12-22 03:58:03 +08:00
|
|
|
INFO("Burning capabilities\n");
|
|
|
|
ret = mpp_caps_set(mpp, &eeprom_table, &caps, &key);
|
|
|
|
if(ret < 0) {
|
|
|
|
ERR("Capabilities burning failed: %d\n", ret);
|
2010-08-18 21:49:24 +08:00
|
|
|
return 1;
|
2014-12-22 03:58:03 +08:00
|
|
|
}
|
|
|
|
INFO("Done\n");
|
2010-08-18 21:49:24 +08:00
|
|
|
if (file != stdin)
|
|
|
|
fclose(file);
|
|
|
|
} else {
|
|
|
|
/* print capabilities to stdout */
|
|
|
|
file = stdout;
|
|
|
|
if (filename) {
|
|
|
|
file = fopen(filename, "w");
|
|
|
|
if (file == NULL) {
|
|
|
|
ERR("Can't create file '%s'\n", filename);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
2012-03-16 04:43:57 +08:00
|
|
|
ret = write_to_file(&eeprom_table, &caps, &key, marker, file);
|
2010-08-18 21:49:24 +08:00
|
|
|
if (ret < 0) {
|
|
|
|
ERR("Failed to write capabilities to file: %d\n", ret);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
if (file != stdout)
|
|
|
|
fclose(file);
|
|
|
|
}
|
2014-12-22 03:58:03 +08:00
|
|
|
astribank_destroy(astribank);
|
2010-08-18 21:49:24 +08:00
|
|
|
return 0;
|
|
|
|
}
|