42 #define BUF ((struct uip_tcpip_hdr *)&uip_buf[UIP_LLH_LEN])
48 #define SLIP_ESC_END 0334
49 #define SLIP_ESC_ESC 0335
51 PROCESS(slip_process,
"SLIP driver");
56 #define SLIP_STATISTICS(statement)
58 uint16_t slip_rubbish, slip_twopackets, slip_overflow, slip_ip_drop;
59 #define SLIP_STATISTICS(statement) statement
63 #define RX_BUFSIZE (UIP_BUFSIZE - UIP_LLH_LEN + 16)
83 static uint8_t state = STATE_TWOPACKETS;
84 static uint16_t begin, end;
85 static uint8_t
rxbuf[RX_BUFSIZE];
86 static uint16_t pkt_end;
88 static void (* input_callback)(void) =
NULL;
91 slip_set_input_callback(
void (*c)(
void))
111 if(i == UIP_TCPIP_HLEN) {
118 }
else if(c == SLIP_ESC) {
131 slip_write(
const void *_ptr,
int len)
133 const uint8_t *ptr = _ptr;
139 for(i = 0; i < len; ++i) {
144 }
else if(c == SLIP_ESC) {
158 begin = end = pkt_end = 0;
164 slip_poll_handler(uint8_t *outbuf, uint16_t blen)
167 if(
rxbuf[begin] ==
'C') {
169 if(begin < end && (end - begin) >= 6
170 && memcmp(&
rxbuf[begin],
"CLIENT", 6) == 0) {
171 state = STATE_TWOPACKETS;
172 memset(&
rxbuf[begin], 0x0, 6);
176 for(i = 0; i < 13; i++) {
182 #ifdef SLIP_CONF_ANSWER_MAC_REQUEST
183 else if(
rxbuf[begin] ==
'?') {
186 char* hexchar =
"0123456789abcdef";
187 if(begin < end && (end - begin) >= 2
188 &&
rxbuf[begin + 1] ==
'M') {
189 state = STATE_TWOPACKETS;
191 rxbuf[begin + 1] = 0;
195 linkaddr_t addr = get_mac_addr();
199 for(j = 0; j < 8; j++) {
213 if(begin != pkt_end) {
216 if(begin < pkt_end) {
217 len = pkt_end - begin;
221 memcpy(outbuf, &
rxbuf[begin], len);
224 len = (RX_BUFSIZE - begin) + (pkt_end - 0);
229 for(i = begin; i < RX_BUFSIZE; i++) {
230 *outbuf++ =
rxbuf[i];
232 for(i = 0; i < pkt_end; i++) {
233 *outbuf++ =
rxbuf[i];
240 if(state == STATE_TWOPACKETS) {
268 if(uip_len == 4 && strncmp((
char*)&uip_buf[
UIP_LLH_LEN],
"?IPA", 4) == 0) {
270 memcpy(&buf[0],
"=IPA", 4);
271 memcpy(&buf[4], &uip_hostaddr, 4);
276 }
else if(uip_len > 0
277 && uip_len == (((uint16_t)(BUF->len[0]) << 8) + BUF->len[1])
280 if(BUF->ipid[0] == 0 && BUF->ipid[1] == 0 && BUF->ipoffset[0] & IP_DF) {
281 static uint16_t ip_id;
282 uint16_t nid = ip_id++;
283 BUF->ipid[0] = nid >> 8;
287 BUF->ipchksum += nid;
288 if(BUF->ipchksum < nid) {
292 #ifdef SLIP_CONF_TCPIP_INPUT
293 SLIP_CONF_TCPIP_INPUT();
299 SLIP_STATISTICS(slip_ip_drop++);
306 #ifdef SLIP_CONF_TCPIP_INPUT
307 SLIP_CONF_TCPIP_INPUT();
319 slip_input_byte(
unsigned char c)
328 case STATE_TWOPACKETS:
332 if(c == SLIP_ESC_END) {
334 }
else if(c == SLIP_ESC_ESC) {
337 state = STATE_RUBBISH;
338 SLIP_STATISTICS(slip_rubbish++);
349 }
else if(c == SLIP_END) {
356 if(begin == pkt_end) {
359 state = STATE_TWOPACKETS;
360 SLIP_STATISTICS(slip_twopackets++);
374 if(next == RX_BUFSIZE) {
378 state = STATE_RUBBISH;
379 SLIP_STATISTICS(slip_overflow++);
388 if(c ==
'T' &&
rxbuf[begin] ==
'C') {
void slip_arch_writeb(unsigned char c)
Copyright (c) 2014, Analog Devices, Inc.
uint16_t uip_ipchksum(void)
Calculate the IP header checksum of the packet header in uip_buf.
uip_len
The length of the packet in the uip_buf buffer.
uIP packet forwarding header file.
void process_poll(struct process *p)
Request a process to be polled.
void tcpip_input(void)
Deliver an incoming packet to the TCP/IP stack.
#define PROCESS_BEGIN()
Define the beginning of a process.
Header file for the uIP TCP/IP stack.
#define NULL
The null pointer.
#define UIP_BUFSIZE
The size of the uIP packet buffer.
#define PROCESS_THREAD(name, ev, data)
Define the body of a process.
#define PROCESS_END()
Define the end of a process.
#define UIP_LLH_LEN
The link level header length.
CCIF uint16_t uip_htons(uint16_t val)
Convert a 16-bit quantity from host byte order to network byte order.
tcirc_buf rxbuf
The RX circular buffer, for storing characters from serial port.
#define PROCESS(name, strname)
Declare a process.
#define UIP_FW_OK
A non-error message that indicates that something went OK.
#define PROCESS_YIELD_UNTIL(c)
Yield the currently running process until a condition occurs.
uip_appdata
Pointer to the application data in the packet buffer.