tools/adflib: build only host variant which is used by Sam440 target
[AROS.git] / workbench / network / stacks / AROSTCP / bsdsocket / net / sana2config.c
blob78304b72a198efd47acdb14208e946963a250bfc
1 /*
2 * Copyright (C) 1993 AmiTCP/IP Group, <amitcp-group@hut.fi>
3 * Helsinki University of Technology, Finland.
4 * All rights reserved.
5 * Copyright (C) 2005 - 2007 The AROS Dev Team
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
19 * MA 02111-1307, USA.
23 #include <conf.h>
25 #include <sys/param.h>
26 #include <sys/socket.h>
27 #include <sys/socketvar.h>
28 #include <net/if.h>
29 #include <net/if_types.h>
30 #include <assert.h>
31 #include <kern/amiga_subr.h>
33 #if NS
34 #error NS is not supported
35 #endif
37 #include "kern/amiga_includes.h"
38 #include <proto/dos.h>
40 #include <netinet/in.h>
41 #include <devices/sana2.h>
42 #include <utility/tagitem.h>
43 #include "net/netdbpaths.h"
44 #include <net/sana2tags.h>
45 #include <net/sana2config.h>
46 #include <net/if_arp.h>
47 #include <net/if_sana.h>
49 static const char template[] = SSC_TEMPLATE;
51 #define CONFIGLINELEN 1024
54 * Parse the configuration
56 struct ssconfig *
57 ssconfig_parse(struct RDArgs *rdargs)
59 struct ssconfig *config = AllocVec(sizeof(*config), MEMF_CLEAR|MEMF_PUBLIC);
61 D(bug("[AROSTCP] ssconfig_parse()\n"));
63 if (config != NULL) {
65 if (ReadArgs(template, (IPTR *)config->args, rdargs)) {
66 config->rdargs = rdargs;
67 config->flags |= SSCF_RDARGS;
68 return config;
69 } else {
70 FreeVec(config);
73 return NULL;
77 * Free the configuration
79 void
80 ssconfig_free(struct ssconfig config[])
82 D(bug("[AROSTCP] ssconfig_free()\n"));
83 if (config->flags & SSCF_RDARGS)
84 FreeArgs(config->rdargs);
85 FreeVec(config);
88 #if 0
89 static int
90 getconfs(BPTR iffh, UBYTE *buf)
92 LONG i, quoted = 0, escaped = 0;
94 D(bug("[AROSTCP] getconfs()\n"));
96 if (FGets(iffh, buf, CONFIGLINELEN - 1)) {
97 for (i = 0; buf[i]; i++) {
98 UBYTE c = buf[i];
99 if (c == '\n') {
100 if (quoted) {
101 return ERROR_UNMATCHED_QUOTES;
103 if (i > 0 && buf[i - 1] == '+') {
104 i--;
105 if (i < CONFIGLINELEN - 2) {
106 if (FGets(iffh, buf + i, CONFIGLINELEN - 1 - i))
107 continue;
108 return IoErr();
110 return ERROR_LINE_TOO_LONG;
112 return 0;
113 } else if (quoted) {
114 if (escaped) {
115 escaped = 0;
116 } else if (c == '*') {
117 escaped = 1;
118 continue;
119 } else if (c == '"') {
120 quoted = 0;
122 } else if (c == ';' || c == '#') {
123 buf[i++] = '\n';
124 buf[i] = '\0';
125 return 0;
126 } else if (escaped) {
127 escaped = 0;
128 } else if (c == '*') {
129 escaped = 1;
130 } else if (c == '"') {
131 quoted = 1;
134 return ERROR_LINE_TOO_LONG;
137 buf[0] = '\0';
138 return IoErr();
140 #endif
143 * Default configuration as per hardware type
145 static const struct wire_defaults {
146 LONG wd_wiretype;
147 LONG wd_iptype; /* IP packet type */
148 WORD wd_ipno; /* SANA-II requests reserved for receiving */
149 WORD wd_writeno; /* SANA-II requests reserved for sending */
150 LONG wd_arptype; /* ARP packet type */
151 WORD wd_arpno; /* SANA-II requests reserved for ARP */
152 WORD wd_arphdr; /* ARP version */
153 WORD wd_ifflags; /* Interface flags */
154 BYTE wd_pad[2];
155 } wire_defaults[] = {
157 S2WireType_Ethernet,
158 ETHERTYPE_IP, 16, 16,
159 ETHERTYPE_ARP, 4, 1,
160 IFF_NOTRAILERS|IFF_BROADCAST|IFF_SIMPLEX,
163 S2WireType_Arcnet,
164 ARCOTYPE_IP, 16, 16,
165 ARCOTYPE_ARP, 4, 7,
166 IFF_NOTRAILERS|IFF_BROADCAST|IFF_SIMPLEX,
169 S2WireType_SLIP,
170 SLIPTYPE_IP, 8, 8,
171 0, 0, 0,
172 IFF_NOTRAILERS|IFF_POINTOPOINT|IFF_NOARP,
175 S2WireType_CSLIP,
176 SLIPTYPE_IP, 8, 8,
177 0, 0, 0,
178 IFF_NOTRAILERS|IFF_POINTOPOINT|IFF_NOARP,
181 S2WireType_PPP,
182 PPPTYPE_IP, 8, 8,
183 0, 0, 0,
184 IFF_NOTRAILERS|IFF_POINTOPOINT|IFF_NOARP,
186 /* Use ethernet as default */
189 ETHERTYPE_IP, 16, 16,
190 ETHERTYPE_ARP, 4, 1,
191 IFF_NOTRAILERS|IFF_BROADCAST|IFF_SIMPLEX,
196 * Initialize sana_softc
198 void
199 ssconfig(struct sana_softc *ifp, struct ssconfig *ifc)
201 const struct ssc_args *args = ifc->args;
202 const struct wire_defaults *wd;
203 LONG wt = ifp->ss_hwtype;
204 LONG reqtotal = 0;
206 D(bug("[AROSTCP] ssconfig()\n"));
208 assert(ifp != NULL);
210 for (wd = wire_defaults; wd->wd_wiretype != 0; wd++) {
211 if (wt == wd->wd_wiretype)
212 break;
215 ifp->ss_ip.type = args->a_iptype ? *args->a_iptype : wd->wd_iptype;
216 reqtotal += ifp->ss_ip.reqno = args->a_ipno ? *args->a_ipno : wd->wd_ipno;
218 ifp->ss_arp.type = args->a_arptype ? *args->a_arptype : wd->wd_arptype;
219 reqtotal += ifp->ss_arp.reqno = args->a_arpno ? *args->a_arpno : wd->wd_arpno;
220 ifp->ss_arp.hrd = args->a_arphdr ? *args->a_arphdr : wd->wd_arphdr;
222 reqtotal += args->a_writeno ? *args->a_writeno : wd->wd_writeno;
224 if (reqtotal > 65535)
225 reqtotal = 65535;
226 ifp->ss_reqno = reqtotal;
229 UWORD ifflags = wd->wd_ifflags;
231 if (args->a_noarp)
232 ifflags |= IFF_NOARP;
233 if (args->a_point2point) {
234 ifflags |= IFF_POINTOPOINT;
235 ifflags &= ~IFF_BROADCAST;
237 if (args->a_nosimplex)
238 ifflags &= ~IFF_SIMPLEX;
239 if (args->a_loopback)
240 ifflags |= IFF_LOOPBACK;
242 ifp->ss_if.if_flags = ifflags;
245 /* Flags for soft_sanac */
246 ifp->ss_cflags = SS_CFLAGS;
248 if (args->a_notrack)
249 ifp->ss_cflags &= ~(SSF_TRACK);
251 /* Set up name */
252 ifp->ss_if.if_name = strcpy(ifp->ss_name, ifc->name);
253 ifp->ss_if.if_unit = ifc->unit;
254 ifp->ss_execname = strcpy((char *)(ifp + 1), ifc->args->a_dev);
255 ifp->ss_execunit = *ifc->args->a_unit;