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 277 278 279 280 281 282 283 284 285 286 287 288
|
/*************************************************
* 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: protocol.c,v 1.32 2001/11/01 15:30:35 root Exp root $";
/*
* $Log: protocol.c,v $
* Revision 1.32 2001/11/01 15:30:35 root
* #
*
* Revision 1.31 2001/11/01 15:30:29 root
* #
*
* Revision 1.30 2001/11/01 15:28:07 root
* #
*
* Revision 1.29 2001/11/01 15:26:45 root
* #
*
* Revision 1.28 2001/11/01 15:24:26 root
* #
*
* Revision 1.27 2001/11/01 15:23:59 root
* #
*
* Revision 1.26 2000/09/26 03:44:29 root
* #
*
* Revision 1.25 2000/09/26 02:31:38 root
* #
*
* Revision 1.24 2000/09/26 01:42:24 root
* #
*
* Revision 1.23 2000/09/26 01:41:20 root
* #
*
* Revision 1.22 2000/09/26 01:41:08 root
* #
*
* Revision 1.21 2000/09/26 01:03:19 root
* #
*
* Revision 1.20 2000/07/29 23:25:58 root
* #
*
* Revision 1.19 2000/07/29 23:25:25 root
* #
*
* Revision 1.18 2000/07/29 23:20:02 root
* #
*
* Revision 1.17 2000/07/23 19:07:49 root
* #
*
* Revision 1.16 2000/07/17 11:59:45 root
* #
*
* Revision 1.15 2000/07/17 10:49:20 root
* #
*
* Revision 1.14 2000/07/17 10:45:38 root
* #
*
* Revision 1.13 2000/07/17 10:43:54 root
* #
*
* Revision 1.12 2000/07/17 10:43:34 root
* #
*
* Revision 1.11 2000/07/16 14:05:28 root
* #
*
* Revision 1.10 2000/07/16 13:18:10 root
* #
*
* Revision 1.1 2000/07/16 13:16:33 root
* #
*
* Revision 1.9 1999/09/13 11:17:35 root
* \#
*
* Revision 1.8 1999/09/13 11:08:34 root
* \#
*
* Revision 1.7 1999/09/13 11:05:27 root
* \#
*
* Revision 1.6 1999/09/13 11:04:13 root
* \#
*
*/
#include "project.h"
/* Process the find frame and xmit a found frame */
void
find_frame (struct llcdrv *lld, struct rpl_packet *in)
{
struct client *c;
struct rpl_packet out;
c = find_client_by_mac (in->mymac);
if (!c)
{
syslog (LOG_ERR, "unknown client %s", ethtoa (in->mymac));
return;
}
c->blocknum = 0;
out.type = RPL_PK_FOUND;
out.flags =
RPL_FL_TMZ | RPL_FL_TSZ | RPL_FL_YOUMAC | RPL_FL_MYMAC | RPL_FL_FRAMELEN |
RPL_FL_WHOAMI | RPL_FL_SAP;
out.themightyzero = in->themightyzero;
out.thesmallzero = 0;
out.whoami = 0;
if (in->framelen < c->framelen)
{
c->framelen = in->framelen;
}
if ((c->blocklen + LLC_RPL_OVERHEAD) > c->framelen)
{
c->blocklen = c->framelen - LLC_RPL_OVERHEAD;
c->blocklen &= ~0x7;
}
c->framelen = out.framelen =
(in->framelen > c->framelen) ? c->framelen : in->framelen;
out.sap = RPL_SAP;
bcopy (in->mymac, out.youmac, ETH_ALEN);
bcopy (lld->mac (lld), out.mymac, ETH_ALEN);
c->state = ST_FIND;
rpl_send_packet (lld, c->mac, &out);
c->state = ST_FOUND;
}
file_data_frame (struct llcdrv *lld, struct client *c)
{
struct rpl_packet out;
int i;
u32 addr = 0x10000;
if (c->state != ST_FILEDATA)
return;
out.flags = RPL_FL_BLOCK | RPL_FL_ADDR | RPL_FL_DATA;
out.type = RPL_PK_FILEDATA;
out.block = c->blocknum;
client_get_block (c, &out);
out.addr.run = c->run_addr;
#ifdef DEBUG
printf ("block %5d, %4d bytes to 0x%08x\n", c->blocknum,
out.datalen, out.addr.load);
#endif
if (client_last_block (c))
{
out.addr.flags = RPL_AD_FLAGS_DONE;
c->state = ST_DONE;
#ifdef DEBUG
printf ("Last block - transfering control to 0x%08x\n", c->run_addr);
#endif
clients_check_status ();
}
else
{
if (c->nospew)
out.addr.flags = RPL_AD_FLAGS_ASK_MORE;
else
out.addr.flags = RPL_AD_FLAGS_MORE;
}
rpl_send_packet (lld, c->mac, &out);
c->blocknum++;
return (i);
}
void
send_file_frame (struct llcdrv *lld, struct rpl_packet *in)
{
struct client *c;
struct rpl_packet out;
c = find_client_by_mac (in->mymac);
if (!c)
{
printf ("Unknown client\n");
return;
}
c->state = ST_SENDFILE;
c->blocknum = in->block;
c->framelen = in->framelen;
syslog (LOG_ERR, "client %s requested block %d", ethtoa (c->mac),
c->blocknum);
client_calc_offsets (c);
c->state = ST_FILEDATA;
clients_check_status (); /* This will upgrade our condition to downloading */
if (c->nospew)
file_data_frame (lld, c);
}
/* rpl.c call this after it's interpreted a packet from the nic */
void
rpl_packet_recvd_callback (struct llcdrv *lld, struct rpl_packet *p)
{
switch (p->type)
{
case RPL_PK_FIND:
if ((p->flags & RPL_FIND_FLAGS) == RPL_FIND_FLAGS)
{
find_frame (lld, p);
}
else
{
syslog (LOG_ERR, "Incomplete FIND frame 0x%x vs 0x%x\n",
p->flags, RPL_FIND_FLAGS);
}
case RPL_PK_FOUND: /*We're not a client */
break;
case RPL_PK_SENDFILE:
if ((p->flags & RPL_SEND_FILE_FLAGS) == RPL_SEND_FILE_FLAGS)
{
send_file_frame (lld, p);
}
else
{
syslog (LOG_ERR,
"Incomplete SEND.FILE.REQUEST frame 0x%x vs 0x%x\n",
p->flags, RPL_SEND_FILE_FLAGS);
}
break;
case RPL_PK_FILEDATA: /*We're not a client */
break;
default:
syslog (LOG_ERR, "Unknown RPL packet type 0x%04x\n", p->type);
}
}
|