xref: /netbsd-src/usr.sbin/mopd/common/common.h (revision 077d1c0f365db1f9f0315d24fd965951eb1d90f2)
1*077d1c0fSandvar /*	$NetBSD: common.h,v 1.10 2021/08/02 12:56:25 andvar Exp $	*/
2fcab4c33Sthorpej 
3ed137f7cScjs /*
4ed137f7cScjs  * Copyright (c) 1993-95 Mats O Jansson.  All rights reserved.
5ed137f7cScjs  *
6ed137f7cScjs  * Redistribution and use in source and binary forms, with or without
7ed137f7cScjs  * modification, are permitted provided that the following conditions
8ed137f7cScjs  * are met:
9ed137f7cScjs  * 1. Redistributions of source code must retain the above copyright
10ed137f7cScjs  *    notice, this list of conditions and the following disclaimer.
11ed137f7cScjs  * 2. Redistributions in binary form must reproduce the above copyright
12ed137f7cScjs  *    notice, this list of conditions and the following disclaimer in the
13ed137f7cScjs  *    documentation and/or other materials provided with the distribution.
14ed137f7cScjs  *
15ed137f7cScjs  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16ed137f7cScjs  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17ed137f7cScjs  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18ed137f7cScjs  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19ed137f7cScjs  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20ed137f7cScjs  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21ed137f7cScjs  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22ed137f7cScjs  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23ed137f7cScjs  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24ed137f7cScjs  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25ed137f7cScjs  *
26*077d1c0fSandvar  *	$NetBSD: common.h,v 1.10 2021/08/02 12:56:25 andvar Exp $
27ed137f7cScjs  *
28ed137f7cScjs  */
29ed137f7cScjs 
30ed137f7cScjs #ifndef _COMMON_H_
31ed137f7cScjs #define _COMMON_H_
32ed137f7cScjs 
33ed137f7cScjs #define MAXDL		16		/* maximum number concurrent load */
34ed137f7cScjs #define IFNAME_SIZE	32		/* maximum size if interface name */
35ed137f7cScjs #define BUFSIZE		1600		/* main receive buffer size	*/
36ed137f7cScjs #define HDRSIZ		22		/* room for 803.2 header	*/
37ed137f7cScjs 
38ed137f7cScjs #ifndef MOP_FILE_PATH
39ed137f7cScjs #define MOP_FILE_PATH	"/tftpboot/mop"
40ed137f7cScjs #endif
41ed137f7cScjs 
42ed137f7cScjs #define DEBUG_ONELINE	1
43ed137f7cScjs #define DEBUG_HEADER	2
44ed137f7cScjs #define DEBUG_INFO	3
45ed137f7cScjs 
46ed137f7cScjs /*
47ed137f7cScjs  * structure per interface
48ed137f7cScjs  *
49ed137f7cScjs  */
50ed137f7cScjs 
51ed137f7cScjs struct if_info {
52ed137f7cScjs 	int	fd;			/* File Descriptor                 */
53ed137f7cScjs 	int	trans;			/* Transport type Ethernet/802.3   */
54ed137f7cScjs 	u_char	eaddr[6];		/* Ethernet addr of this interface */
55ed137f7cScjs 	char	if_name[IFNAME_SIZE];	/* Interface Name		   */
56732d96f1Sjoerg 	int	(*iopen)(const char *, int, u_short, int);
57b3f8f590Slukem 					/* Interface Open Routine	   */
58732d96f1Sjoerg 	int	(*write)(int, const u_char *, int, int);
59b3f8f590Slukem 					/* Interface Write Routine	   */
60732d96f1Sjoerg 	void	(*read)(void);	/* Interface Read Routine          */
61ed137f7cScjs 	struct if_info *next;		/* Next Interface		   */
62ed137f7cScjs };
63ed137f7cScjs 
64ed137f7cScjs #define DL_STATUS_FREE		 0
65ed137f7cScjs #define DL_STATUS_READ_IMGHDR	 1
66ed137f7cScjs #define DL_STATUS_SENT_MLD	 2
67ed137f7cScjs #define DL_STATUS_SENT_PLT	 3
68ed137f7cScjs 
69e96b77f0Sthorpej typedef enum {
70e96b77f0Sthorpej 	IMAGE_TYPE_MOP,			/* MOP image */
71e96b77f0Sthorpej 	IMAGE_TYPE_AOUT,		/* a.out image */
72e96b77f0Sthorpej 	IMAGE_TYPE_ELF32		/* Elf32 image */
73e96b77f0Sthorpej } mopd_imagetype;
74e96b77f0Sthorpej 
75ed137f7cScjs struct dllist {
76ed137f7cScjs 	u_char		status;		/* Status byte			*/
77ed137f7cScjs 	struct if_info *ii;		/* interface pointer		*/
78*077d1c0fSandvar 	u_char		eaddr[6];	/* targets ethernet address	*/
79ed137f7cScjs 	int		ldfd;		/* filedescriptor for loadfile	*/
80ed137f7cScjs 	u_short		dl_bsz;		/* Data Link Buffer Size	*/
81ed137f7cScjs 	int		timeout;	/* Timeout counter		*/
82ed137f7cScjs 	u_char		count;		/* Packet Counter		*/
83b3f8f590Slukem 	u_int32_t	loadaddr;	/* Load Address			*/
84b3f8f590Slukem 	u_int32_t	xferaddr;	/* Transfer Address		*/
85b3f8f590Slukem 	u_int32_t	nloadaddr;	/* Next Load Address		*/
86b3f8f590Slukem 	off_t		lseek;		/* Seek before last read	*/
87e96b77f0Sthorpej 	mopd_imagetype	image_type;	/* what type of image is it?	*/
88e96b77f0Sthorpej 
89e96b77f0Sthorpej 	/* For Elf32 files */
9063e6bdedSthorpej 	int		e_machine;	/* Machine ID			*/
91e96b77f0Sthorpej 	int		e_nsec;		/* number of program sections	*/
92e96b77f0Sthorpej #define	SEC_MAX	4
93e96b77f0Sthorpej 	struct {
94e96b77f0Sthorpej 		off_t s_foff;		/* file offset of section	*/
95e96b77f0Sthorpej 		u_int32_t s_vaddr;	/* virtual address of section	*/
96e96b77f0Sthorpej 		u_int32_t s_fsize;	/* file size of section		*/
97e96b77f0Sthorpej 		u_int32_t s_msize;	/* memory size of section	*/
98e96b77f0Sthorpej 		u_int32_t s_pad;	/* padding until next section	*/
99e96b77f0Sthorpej 		u_int32_t s_loff;	/* logical offset into image	*/
100e96b77f0Sthorpej 	} e_sections[SEC_MAX];		/* program sections		*/
101e96b77f0Sthorpej 	u_int32_t	e_curpos;	/* current logical position	*/
102e96b77f0Sthorpej 	int		e_cursec;	/* current section */
103e96b77f0Sthorpej 
104e96b77f0Sthorpej 	/* For a.out files */
105e96b77f0Sthorpej 	int		a_mid;		/* Machine ID			*/
106b3f8f590Slukem 	u_int32_t	a_text;		/* Size of text segment		*/
107b3f8f590Slukem 	u_int32_t	a_text_fill;	/* Size of text segment fill	*/
108b3f8f590Slukem 	u_int32_t	a_data;		/* Size of data segment		*/
109b3f8f590Slukem 	u_int32_t	a_data_fill;	/* Size of data segment fill	*/
110b3f8f590Slukem 	u_int32_t	a_bss;		/* Size of bss segment		*/
111b3f8f590Slukem 	u_int32_t	a_bss_fill;	/* Size of bss segment fill	*/
112b3f8f590Slukem 	off_t		a_lseek;	/* Keep track of pos in newfile */
113ed137f7cScjs };
114ed137f7cScjs 
115b3f8f590Slukem #endif /* _COMMON_H_ */
116