1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276
|
/*************************************************
* rpld - an IBM style RIPL server *
*************************************************/
/* Copyright (c) 1999,2000,2001 James McKenzie.
* All rights reserved
* Copyright (c) 1998,2000,2001 Christopher Lightfoot.
* All rights reserved
*
* By using this file, you agree to the terms and conditions set
* forth in the LICENCE file which can be found at the top level of
* the rpld distribution.
*
* IBM is a trademark of IBM corp.
*
*/
static char rcsid[] = "$Id: llc-nit.c,v 1.8 2001/11/01 15:30:29 root Exp $";
/*
* $Log: llc-nit.c,v $
* Revision 1.8 2001/11/01 15:30:29 root
* #
*
* Revision 1.7 2001/11/01 15:28:23 root
* #
*
* Revision 1.6 2001/11/01 15:26:45 root
* #
*
* Revision 1.5 2001/11/01 15:26:29 root
* #
*
* Revision 1.4 2001/11/01 15:23:59 root
* #
*
* Revision 1.3 2000/09/26 04:06:07 root
* #
*
* Revision 1.2 2000/09/26 03:48:23 root
* #
*
* Revision 1.1 2000/09/26 03:44:29 root
* #
*
* Revision 1.10 2000/07/17 11:59:45 root
* #
*
* Revision 1.9 2000/07/17 10:43:34 root
* #
*
* Revision 1.8 2000/07/16 14:05:28 root
* #
*
* Revision 1.7 2000/07/16 13:18:10 root
* #
*
* Revision 1.1 2000/07/16 13:16:33 root
* #
*
* Revision 1.6 1999/09/13 11:17:35 root
* \#
*
* Revision 1.5 1999/09/13 11:05:27 root
* \#
*
* Revision 1.4 1999/09/13 11:04:13 root
* \#
*
*/
#include "project.h"
#include "llc.h"
#include "nit.h"
#define LLC_HDR_LEN 3
#define LLC_UIC 0x3
/* The LLC-1 headers as it comes off the wire */
struct llchdr
{
unsigned char h_dsap;
unsigned char h_ssap;
unsigned char h_flags;
};
struct llcdrv_nit
{
LLCDRV;
struct nit *n;
int sap;
};
#ifdef DEBUG
static void
hexdump (char *p, unsigned char *buf, int l)
{
int i;
for (i = 0; i < l; ++i)
{
if ((i % 16) == 0)
{
printf ("%s: ", p);
}
printf ("%02x ", buf[i]);
if ((i % 16) == 15)
{
printf ("\n");
}
}
printf ("\n");
}
#endif
static int
llc_nit_send (struct llcdrv *llc, unsigned char *dmac, unsigned char dsap,
unsigned char *buf, int len)
{
struct llcdrv_nit *llc_nit = (struct llcdrv_nit *) llc;
unsigned char mybuf[MAX_FRAME_LEN];
struct llchdr *h = (struct llchdr *) mybuf;
int llclen;
#ifdef DEBUG
printf ("Got %d bytes from upper layer\n", len);
// hexdump("write",buf,len);
#endif
/*
bcopy (dmac, h->h_dest, ETH_ALEN);
bcopy (nit_mac(llc_nit->n), h->h_source, ETH_ALEN);
h->h_len = htons (len + LLC_SAP_LEN);
*/
h->h_ssap = llc_nit->sap;
h->h_dsap = dsap;
h->h_flags = LLC_UIC;
bcopy (buf, mybuf + LLC_HDR_LEN, len);
llclen = len + LLC_HDR_LEN;
if (nit_send (llc_nit->n, mybuf, llclen, dmac) == llclen)
{
return len;
}
return -1;
}
static int
llc_nit_recv (struct llcdrv *llc, unsigned char *buf, int blen,
unsigned char *smac, unsigned char *ssap, struct timeval *tv)
{
struct llcdrv_nit *llc_nit = (struct llcdrv_nit *) llc;
unsigned char mybuf[MAX_FRAME_LEN + 20];
unsigned char *myptr = &mybuf[20];
#define mylen (MAX_FRAME_LEN-20)
struct llchdr *h = (struct llchdr *) myptr;
int llclen;
int len;
do
{
do
{
len = nit_recv (llc_nit->n, myptr, mylen, smac, tv);
if (len <= 0)
{
return len;
}
}
while ((len <= LLC_HDR_LEN) || (len > MAX_FRAME_LEN));
llclen = len;
#ifdef DEBUG
if (smac)
printf ("llc-nit-recv: source: %s ", ethtoa (smac));
printf ("len: 0x%04x ", llclen);
printf ("dsap:%02x ssap:%02x flags:%02x \n", h->h_dsap, h->h_ssap,
h->h_flags);
#endif
}
while (h->h_dsap != llc_nit->sap);
#ifdef DEBUG
hexdump ("read", myptr, len);
#endif
if (ssap)
*ssap = h->h_ssap;
llclen -= LLC_HDR_LEN;
bcopy (myptr + LLC_HDR_LEN, buf, llclen);
#ifdef DEBUG
printf ("Returning %d bytes to upper layer\n", llclen);
hexdump ("read", buf, llclen);
#endif
return llclen;
}
static int
llc_nit_add_multicast (struct llcdrv *llc, unsigned char *mac)
{
struct llcdrv_nit *llc_nit = (struct llcdrv_nit *) llc;
return nit_multicast (llc_nit->n, mac);
}
static unsigned char *
llc_nit_mac (struct llcdrv *llc)
{
struct llcdrv_nit *llc_nit = (struct llcdrv_nit *) llc;
return nit_mac (llc_nit->n);
}
static void
llc_nit_close (struct llcdrv *llc)
{
struct llcdrv_nit *llc_nit = (struct llcdrv_nit *) llc;
nit_close (llc_nit->n);
free (llc_nit);
}
struct llcdrv *
llc_open (unsigned char sap, char *name)
{
struct llcdrv_nit *llc;
syslog (LOG_ERR, "RPLD LLC 802.2 over NIT support %s", rcsid);
llc = malloc (sizeof (struct llcdrv_nit));
bzero (llc, sizeof (struct llcdrv_nit));
llc->n = nit_open (name);
if (!llc->n)
{
free (llc);
return NULL;
}
llc->sap = sap;
llc->recv = llc_nit_recv;
llc->send = llc_nit_send;
llc->mac = llc_nit_mac;
llc->add_multicast = llc_nit_add_multicast;
llc->close = llc_nit_close;
return (struct llcdrv *) llc;
}
|