blob: da137d3f5f5dc9e67dac05658c618f25dd855f33 [file] [log] [blame]
adamdunkels9819dca2003-04-25 08:48:25 +00001/*
adamdunkels43aff6f2004-08-13 08:38:46 +00002 * Copyright (c) 2004, Adam Dunkels.
adamdunkels9819dca2003-04-25 08:48:25 +00003 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
adamdunkels43aff6f2004-08-13 08:38:46 +000013 * 3. The name of the author may not be used to endorse or promote
adamdunkels9819dca2003-04-25 08:48:25 +000014 * products derived from this software without specific prior
15 * written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
18 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
21 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
23 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
25 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
26 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 *
adamdunkels43aff6f2004-08-13 08:38:46 +000029 * This file is part of the Contiki OS
adamdunkels9819dca2003-04-25 08:48:25 +000030 *
adamdunkels0ff4dae2004-09-03 10:04:30 +000031 * $Id: slip-drv.c,v 1.8 2004/09/03 10:04:30 adamdunkels Exp $
adamdunkels9819dca2003-04-25 08:48:25 +000032 *
33 */
34
adamdunkels43aff6f2004-08-13 08:38:46 +000035#include "contiki.h"
adamdunkelsf7f5a402003-07-31 23:17:07 +000036#include "rs232dev.h"
adamdunkels9819dca2003-04-25 08:48:25 +000037
adamdunkels0ff4dae2004-09-03 10:04:30 +000038#include "packet-service.h"
39
adamdunkels43aff6f2004-08-13 08:38:46 +000040static void output(u8_t *hdr, u16_t hdrlen, u8_t *data, u16_t datalen);
adamdunkels9819dca2003-04-25 08:48:25 +000041
adamdunkels43aff6f2004-08-13 08:38:46 +000042static const struct packet_service_state state =
43 {
44 PACKET_SERVICE_VERSION,
45 output
46 };
adamdunkels9819dca2003-04-25 08:48:25 +000047
adamdunkels43aff6f2004-08-13 08:38:46 +000048EK_EVENTHANDLER(eventhandler, ev, data);
49EK_POLLHANDLER(pollhandler);
adamdunkels0ff4dae2004-09-03 10:04:30 +000050EK_PROCESS(proc, PACKET_SERVICE_NAME ": SLIP", EK_PRIO_HIGH,
adamdunkels43aff6f2004-08-13 08:38:46 +000051 eventhandler, pollhandler, (void *)&state);
adamdunkels9819dca2003-04-25 08:48:25 +000052
adamdunkels43aff6f2004-08-13 08:38:46 +000053/*---------------------------------------------------------------------------*/
54LOADER_INIT_FUNC(tapdev_service_init, arg)
adamdunkels9819dca2003-04-25 08:48:25 +000055{
adamdunkels68f6f4b2003-08-24 22:41:55 +000056 arg_free(arg);
adamdunkels43aff6f2004-08-13 08:38:46 +000057 ek_service_start(PACKET_SERVICE_NAME, &proc);
adamdunkels9819dca2003-04-25 08:48:25 +000058}
adamdunkels43aff6f2004-08-13 08:38:46 +000059/*---------------------------------------------------------------------------*/
60static void
61output(u8_t *hdr, u16_t hdrlen, u8_t *data, u16_t datalen)
adamdunkels9819dca2003-04-25 08:48:25 +000062{
adamdunkels43aff6f2004-08-13 08:38:46 +000063 rs232dev_send();
64}
65/*---------------------------------------------------------------------------*/
66EK_EVENTHANDLER(eventhandler, ev, data)
67{
68 switch(ev) {
69 case EK_EVENT_INIT:
70 case EK_EVENT_REPLACE:
71 rs232dev_init();
72 break;
73 case EK_EVENT_REQUEST_REPLACE:
74 ek_replace((struct ek_proc *)data, NULL);
adamdunkels0ff4dae2004-09-03 10:04:30 +000075 rs232dev_unload();
adamdunkels43aff6f2004-08-13 08:38:46 +000076 LOADER_UNLOAD();
77 break;
78 case EK_EVENT_REQUEST_EXIT:
79 ek_exit();
adamdunkels0ff4dae2004-09-03 10:04:30 +000080 rs232dev_unload();
adamdunkels43aff6f2004-08-13 08:38:46 +000081 LOADER_UNLOAD();
82 break;
83 default:
84 break;
adamdunkels9819dca2003-04-25 08:48:25 +000085 }
86}
adamdunkels43aff6f2004-08-13 08:38:46 +000087/*---------------------------------------------------------------------------*/
88EK_POLLHANDLER(pollhandler)
89{
90 uip_len = rs232dev_poll();
91 if(uip_len > 0) {
92 tcpip_input();
93 }
94
95}
96/*---------------------------------------------------------------------------*/