43 #define BUF ((struct uip_tcpip_hdr *)&uip_buf[UIP_LLH_LEN])
49 #define SLIP_ESC_END 0334
50 #define SLIP_ESC_ESC 0335
52 PROCESS(slip_process,
"SLIP driver");
57 #define SLIP_STATISTICS(statement)
59 u16_t slip_rubbish, slip_twopackets, slip_overflow, slip_ip_drop;
60 #define SLIP_STATISTICS(statement) statement
64 #define RX_BUFSIZE (UIP_BUFSIZE - UIP_LLH_LEN + 16)
84 static u8_t state = STATE_TWOPACKETS;
85 static u16_t begin, end;
86 static u8_t
rxbuf[RX_BUFSIZE];
89 static void (* input_callback)(void) =
NULL;
92 slip_set_input_callback(
void (*c)(
void))
108 slip_arch_writeb(SLIP_END);
112 if(i == UIP_TCPIP_HLEN) {
117 slip_arch_writeb(SLIP_ESC);
119 }
else if(c == SLIP_ESC) {
120 slip_arch_writeb(SLIP_ESC);
125 slip_arch_writeb(SLIP_END);
132 slip_write(
const void *_ptr,
int len)
134 const u8_t *ptr = _ptr;
138 slip_arch_writeb(SLIP_END);
140 for(i = 0; i < len; ++i) {
143 slip_arch_writeb(SLIP_ESC);
145 }
else if(c == SLIP_ESC) {
146 slip_arch_writeb(SLIP_ESC);
151 slip_arch_writeb(SLIP_END);
159 begin = end = pkt_end = 0;
165 slip_poll_handler(u8_t *outbuf, u16_t blen)
168 if(
rxbuf[begin] ==
'C') {
170 if(begin < end && (end - begin) >= 6
171 && memcmp(&
rxbuf[begin],
"CLIENT", 6) == 0) {
172 state = STATE_TWOPACKETS;
173 memset(&
rxbuf[begin], 0x0, 6);
177 for(i = 0; i < 13; i++) {
178 slip_arch_writeb(
"CLIENTSERVER\300"[i]);
183 #ifdef SLIP_CONF_ANSWER_MAC_REQUEST
184 else if(
rxbuf[begin] ==
'?') {
187 char* hexchar =
"0123456789abcdef";
188 if(begin < end && (end - begin) >= 2
189 &&
rxbuf[begin + 1] ==
'M') {
190 state = STATE_TWOPACKETS;
192 rxbuf[begin + 1] = 0;
196 rimeaddr_t addr = get_mac_addr();
198 slip_arch_writeb(
'!');
199 slip_arch_writeb(
'M');
200 for(j = 0; j < 8; j++) {
201 slip_arch_writeb(hexchar[addr.u8[j] >> 4]);
202 slip_arch_writeb(hexchar[addr.u8[j] & 15]);
204 slip_arch_writeb(SLIP_END);
214 if(begin != pkt_end) {
217 if(begin < pkt_end) {
218 len = pkt_end - begin;
222 memcpy(outbuf, &
rxbuf[begin], len);
225 len = (RX_BUFSIZE - begin) + (pkt_end - 0);
230 for(i = begin; i < RX_BUFSIZE; i++) {
231 *outbuf++ =
rxbuf[i];
233 for(i = 0; i < pkt_end; i++) {
234 *outbuf++ =
rxbuf[i];
241 if(state == STATE_TWOPACKETS) {
269 if(uip_len == 4 && strncmp((
char*)&uip_buf[
UIP_LLH_LEN],
"?IPA", 4) == 0) {
271 memcpy(&buf[0],
"=IPA", 4);
272 memcpy(&buf[4], &uip_hostaddr, 4);
277 }
else if(uip_len > 0
278 && uip_len == (((u16_t)(BUF->len[0]) << 8) + BUF->len[1])
281 if(BUF->ipid[0] == 0 && BUF->ipid[1] == 0 && BUF->ipoffset[0] & IP_DF) {
284 BUF->ipid[0] = nid >> 8;
288 BUF->ipchksum += nid;
289 if(BUF->ipchksum < nid) {
293 #ifdef SLIP_CONF_TCPIP_INPUT
294 SLIP_CONF_TCPIP_INPUT();
300 SLIP_STATISTICS(slip_ip_drop++);
307 #ifdef SLIP_CONF_TCPIP_INPUT
308 SLIP_CONF_TCPIP_INPUT();
320 slip_input_byte(
unsigned char c)
329 case STATE_TWOPACKETS:
333 if(c == SLIP_ESC_END) {
335 }
else if(c == SLIP_ESC_ESC) {
338 state = STATE_RUBBISH;
339 SLIP_STATISTICS(slip_rubbish++);
350 }
else if(c == SLIP_END) {
357 if(begin == pkt_end) {
360 state = STATE_TWOPACKETS;
361 SLIP_STATISTICS(slip_twopackets++);
375 if(next == RX_BUFSIZE) {
379 state = STATE_RUBBISH;
380 SLIP_STATISTICS(slip_overflow++);
389 if(c ==
'T' &&
rxbuf[begin] ==
'C') {