Subversion Repositories shark

Rev

Rev 633 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
633 giacomo 1
/*
2
 * Project: S.Ha.R.K.
3
 *
4
 * Coordinators:
5
 *   Giorgio Buttazzo    <giorgio@sssup.it>
6
 *   Paolo Gai           <pj@gandalf.sssup.it>
7
 *
8
 * Authors     :
9
 *   Paolo Gai           <pj@gandalf.sssup.it>
10
 *   Massimiliano Giorgi <massy@gandalf.sssup.it>
11
 *   Luca Abeni          <luca@gandalf.sssup.it>
12
 *   (see the web pages for full authors list)
13
 *
14
 * ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy)
15
 *
16
 * http://www.sssup.it
17
 * http://retis.sssup.it
18
 * http://shark.sssup.it
19
 */
20
 
21
/**
22
 ------------
966 pj 23
 CVS :        $Id: udpip.h,v 1.2 2005-02-25 11:04:03 pj Exp $
633 giacomo 24
 
25
 File:        $File$
966 pj 26
 Revision:    $Revision: 1.2 $
27
 Last update: $Date: 2005-02-25 11:04:03 $
633 giacomo 28
 ------------
29
 
30
**/
31
 
32
/*
33
 * Copyright (C) 2000 Luca Abeni
34
 *
35
 * This program is free software; you can redistribute it and/or modify
36
 * it under the terms of the GNU General Public License as published by
37
 * the Free Software Foundation; either version 2 of the License, or
38
 * (at your option) any later version.
39
 *
40
 * This program is distributed in the hope that it will be useful,
41
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
42
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
43
 * GNU General Public License for more details.
44
 *
45
 * You should have received a copy of the GNU General Public License
46
 * along with this program; if not, write to the Free Software
47
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
48
 *
49
 */
50
 
51
/* Project:     HARTIK 3.0                                      */
52
/* Description: Hard Real TIme Kernel for 8086 compatible       */
53
/* Author:      Luca Abeni                                      */
54
/* Date:        25/9/96                                         */
55
 
56
/* File:        UDPIP.h                                         */
57
/* Revision:    4.0                                             */
58
 
59
 
60
 
61
/* First, include the net general definitions */
62
 
966 pj 63
#include <hartport/hartport/hartport.h>
633 giacomo 64
#include <drivers/net.h>
65
 
66
#ifndef __UDPIP_H__
67
#define __UDPIP_H__
68
 
69
#ifdef __cplusplus
70
extern "C" {
71
#endif
72
 
73
/*#define net_setudpip(m,localaddr) {net_setprotocol(&m, ip_init, localaddr); net_setprotocol(&m, udp_init, NULL);}*/
74
 
75
#define net_setudpip(m,localaddr,broadcastaddr) {struct ip_params p={localaddr,broadcastaddr};net_setprotocol(&m, ip_init, &p); net_setprotocol(&m, udp_init, NULL);}
76
 
77
struct ip_params{
78
    char*localAddr;
79
    char*broadcastAddr;
80
};
81
 
82
typedef struct ip_addr{
83
    BYTE ad[4];
84
} IP_ADDR;
85
 
86
#define IP_ERROR_BASE   (ETH_ERROR_BASE + 20)
87
#define IP_INIT_ERROR   (0 + IP_ERROR_BASE)
88
 
89
#define IP_UDP_TYPE     17
90
#define IP_TCP_TYPE     6
91
 
92
#define setIpAddr(q,w) memcpy(q.ad,w.ad,sizeof(IP_ADDR))
93
#define getVers(b)      ((b) >> 4)
94
#define getHlen(b)      (b & 0x0f)
95
#define getFlags(w)     ((w) >> 13)
96
#define getFrOffset(w)  (w & 0x1fff)
97
 
98
typedef struct ip_header {
99
    BYTE vers_hlen;
100
    BYTE servType;
101
    WORD lenght;
102
    WORD ident;
103
    WORD flags_frOffset;
104
    BYTE ttl;
105
    BYTE protocol;
106
    WORD headChecksum;
107
    IP_ADDR source;
108
    IP_ADDR dest;
109
} IP_HEADER;
110
 
111
#define IP_MAX_ENTRIES 2
112
typedef struct ip_table{
113
    BYTE protocol;
114
    void (*rfun)(void *m);
115
} IP_TABLE;
116
 
117
void ip_print_header(IP_HEADER *p);
118
int ip_compAddr(IP_ADDR ip1, IP_ADDR ip2);
119
int ip_str2addr(char *a, IP_ADDR *ip);
120
void *ip_getFDB(void *pkt);
121
int ip_setProtocol(BYTE p, void (*recv)(void *m));
122
void ip_send(IP_ADDR dest, void *pkt, WORD len);
123
void ip_init(void *p);/*pass a struct ip_params* */
124
IP_ADDR *ip_getAddr();
125
 
126
 
127
/***************************************************************************/
128
/*                                                                         */
129
/*                              UDP                                        */
130
/*                                                                         */
131
/***************************************************************************/
132
 
133
typedef struct udp_addr{
134
    IP_ADDR s_addr;
135
    WORD s_port;
136
} UDP_ADDR;
137
 
138
 
139
typedef struct udp_header{
140
    WORD s_port;
141
    WORD d_port;
142
    WORD mlen;
143
    WORD checksum;
144
} UDP_HEADER;
145
 
146
typedef struct pseudo_hd {
147
    IP_ADDR source;
148
    IP_ADDR dest;
149
    BYTE zero;
150
    BYTE protocoll;
151
    WORD len;
152
} PSEUDO_HD;
153
 
154
typedef struct udp_msg{
155
    WORD mlen;
156
    UDP_ADDR addr;
157
    void *buff;
158
} UDP_MSG;
159
 
160
typedef struct udp_table{
161
    WORD port;
162
    BYTE valid;
163
    PORT hport;
164
    PORT pport;
165
    BYTE notify;
166
    int (*notify_fun)(int l, BYTE *buff, void *p);
167
    void *notify_par;
168
} UDP_TABLE;
169
 
170
void udp_init(void *dummy);
171
int udp_recvfrom(int s, void *buff, UDP_ADDR *from);
172
int udp_sendto(int s, void *buff, int nbytes, UDP_ADDR *to);
173
int udp_bind(UDP_ADDR *a, IP_ADDR *bindlist);
174
int udp_notify(int s, int (*f)(int len, BYTE *buff, void *p), void *p);
175
 
176
#ifdef __cplusplus
177
};
178
#endif
179
 
180
 
181
#endif
182