/* $Id: hps_setid.c,v 2.3 91/09/03 17:37:58 annette Exp $ */
/****************************************************************/
/*	hps_setid.c:  HPS Host ID "Setter"							*/
/****************************************************************/
/*																*/
/*                 Confidential Information                     */
/*      Limited Distribution to Authorized Persons Only         */
/*     Created 1987 and Protected as an Unpublished Work        */
/*          Under the U.S. Copyright Act of 1976.               */
/*         Copyright (c) 1987, Systech Corporation         		*/
/*                  All Rights Reserved                         */
/*																*/
/*	THIS SOFTWARE IS LICENSED BY AND IS THE	CONFIDENTIAL AND 	*/
/*	PROPRIETARY PROPERTY OF SYSTECH COMPUTER CORPORATION AND 	*/
/*	MAY NOT, WITHOUT THE PRIOR WRITTEN CONSENT OF SYSTECH 		*/
/*	COMPUTER CORPORATION, BE REPRODUCED, USED OR DISCLOSED 		*/
/*	EXCEPT IN ACCORDANCE WITH A SYSTECH COMPUTER CORPORATION 	*/
/*	SOFTWARE LICENSE AGREEMENT.									*/
/****************************************************************/
/*																*/
/*   This program sets a host ID through the on-board network	*/
/*   interface task.											*/
/*   There are two input parameters:  host ID in hex and raw	*/
/*   device name.  If the second parameter is not provided,		*/
/*   the defaule RAW_DEVNAME is used instead.					*/
/*																*/
/****************************************************************/

/* #define DEBUG */

#include <stdio.h>
#include <a.out.h>
#include "hps.types.h"
#include "hps.iocb.h"
#include "hps.ioctl.h"
#include "hps.conf.h"
#include "hps.onb.h"
#include "hps.net.h"
#include "hps.ccdl.h"

char  hps_intel		= 0;			/* host byte ordering	*/
static long mailbox = 0;

int hpsfd;

extern int errno;

main(argc, argv)
int argc;
char **argv;
{
	char *dldev;
	int cd;
	int host_id;
	short tmp;

	tmp = 0;
	hps_intel = *(char *)&tmp;

	if (argc > 3 || argc < 2)
	{
		fprintf(stderr,
			"Usage: hps_setid host_ID <raw_device>\n");
		exit(1);
	}

	sscanf (argv[1], "%x", &host_id);
	if ( argc > 2 )
		dldev = argv[2];
	else
		dldev = RAW_DEVNAME;

#	ifdef DEBUG
		fprintf(stderr,"host_id = %x\n",host_id);
		fprintf(stderr,"dldev = %s\n",dldev);
#	endif

	/* Open HPS raw driver */
	if ((hpsfd = open(dldev, 2)) < 0)
	{
		fprintf(stderr, "%s: Cannot open device %s\n", argv[0], dldev);
		if (errno)
			perror(argv[0]);
		exit(1);
	}

#	ifdef DEBUG
		fprintf(stderr, "%s: Open nif host ID\n", pname);
#	endif

	/*
	 * Open host ID minor device of network interface task.
	 */
	if (cd = nif_setid(hpsfd, host_id & 0xff, mailbox))
	{
		fprintf(stderr, 
		 "%s: Cannot open network interface module\n", argv[0]);

		if (errno)
			perror(argv[0]);
		else
			errtab(mailbox >> 16, argv[0]);
		exit(1);
	}
	close ( hpsfd );

#	ifdef DEBUG
		fprintf(stderr, "hostid(): Done\n");
#	endif

	return ( 0 );
}

/*
 * MODIFICATION HISTORY:
 *
 * $Log:	hps_setid.c,v $
 * Revision 1.1.2.1  92/06/24  13:53:35  marker
 * Branch RISCOS_5_01_2_FIXES off of trunk.
 * 
 * Revision 2.3  91/09/03  17:37:58  annette
 * Changed error message handling.
 * INTERNAL
 * 
 * Revision 2.2  91/01/10  17:22:55  dave
 * Modify header; add footer.
 * COSMETIC
 * 
 */
