2 * Copyright (C) 1993 AmiTCP/IP Group, <amitcp-group@hut.fi>
3 * Helsinki University of Technology, Finland.
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,
25 #include <sys/param.h>
26 #include <sys/socket.h>
27 #include <sys/socketvar.h>
29 #include <net/if_types.h>
31 #include <kern/amiga_subr.h>
34 #error NS is not supported
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
57 ssconfig_parse(struct RDArgs
*rdargs
)
59 struct ssconfig
*config
= AllocVec(sizeof(*config
), MEMF_CLEAR
|MEMF_PUBLIC
);
61 D(bug("[AROSTCP] ssconfig_parse()\n"));
65 if (ReadArgs(template, (IPTR
*)config
->args
, rdargs
)) {
66 config
->rdargs
= rdargs
;
67 config
->flags
|= SSCF_RDARGS
;
77 * Free the configuration
80 ssconfig_free(struct ssconfig config
[])
82 D(bug("[AROSTCP] ssconfig_free()\n"));
83 if (config
->flags
& SSCF_RDARGS
)
84 FreeArgs(config
->rdargs
);
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
++) {
101 return ERROR_UNMATCHED_QUOTES
;
103 if (i
> 0 && buf
[i
- 1] == '+') {
105 if (i
< CONFIGLINELEN
- 2) {
106 if (FGets(iffh
, buf
+ i
, CONFIGLINELEN
- 1 - i
))
110 return ERROR_LINE_TOO_LONG
;
116 } else if (c
== '*') {
119 } else if (c
== '"') {
122 } else if (c
== ';' || c
== '#') {
126 } else if (escaped
) {
128 } else if (c
== '*') {
130 } else if (c
== '"') {
134 return ERROR_LINE_TOO_LONG
;
143 * Default configuration as per hardware type
145 static const struct wire_defaults
{
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 */
155 } wire_defaults
[] = {
158 ETHERTYPE_IP
, 16, 16,
160 IFF_NOTRAILERS
|IFF_BROADCAST
|IFF_SIMPLEX
,
166 IFF_NOTRAILERS
|IFF_BROADCAST
|IFF_SIMPLEX
,
172 IFF_NOTRAILERS
|IFF_POINTOPOINT
|IFF_NOARP
,
178 IFF_NOTRAILERS
|IFF_POINTOPOINT
|IFF_NOARP
,
184 IFF_NOTRAILERS
|IFF_POINTOPOINT
|IFF_NOARP
,
186 /* Use ethernet as default */
189 ETHERTYPE_IP
, 16, 16,
191 IFF_NOTRAILERS
|IFF_BROADCAST
|IFF_SIMPLEX
,
196 * Initialize sana_softc
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
;
206 D(bug("[AROSTCP] ssconfig()\n"));
210 for (wd
= wire_defaults
; wd
->wd_wiretype
!= 0; wd
++) {
211 if (wt
== wd
->wd_wiretype
)
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)
226 ifp
->ss_reqno
= reqtotal
;
229 UWORD ifflags
= wd
->wd_ifflags
;
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
;
249 ifp
->ss_cflags
&= ~(SSF_TRACK
);
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
;