Subversion Repositories shark

Rev

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

Rev Author Line No. Line
1063 tullio 1
 
2
/*
3
 * This program is free software; you can redistribute it and/or modify
4
 * it under the terms of the GNU General Public License as published by
5
 * the Free Software Foundation; either version 2 of the License, or
6
 * (at your option) any later version.
7
 *
8
 * This program is distributed in the hope that it will be useful,
9
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
 * GNU General Public License for more details.
12
 *
13
 * You should have received a copy of the GNU General Public License
14
 * along with this program; if not, write to the Free Software
15
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
 *
17
 */
18
 
262 giacomo 19
#ifndef __TFTP_H
20
#define __TFTP_H        1
21
 
22
#include <string.h>
23
#include <stdlib.h>
24
#include <stdio.h>
25
#include <ll/sys/types.h>
26
#include <drivers/udpip.h>
27
 
967 pj 28
#include "sem/sem/sem.h"
262 giacomo 29
 
30
#define BASE_X   (40)
31
 
32
/* Real-time constraints for the sender and receiver tasks */
33
#define TFTP_UPLOAD_SENDER_PERIOD    (2000000)
34
#define TFTP_UPLOAD_SENDER_WCET      (1000000)
35
#define TFTP_UPLOAD_SENDER_MET        (500000)
36
 
37
/* opcodes options */
38
#define TFTP_READ_REQUEST   (1)
39
#define TFTP_WRITE_REQUEST  (2)
40
#define TFTP_DATA           (3)
41
#define TFTP_ACK            (4)
42
#define TFTP_ERROR          (5)
43
 
44
/* Default TFTP protocol error codes */
45
#define TFTP_ERR_NOT_DEFINED        (0)   /* Not defined, see error message (if any) */
46
#define TFTP_ERR_FILE_NOR_FOUND     (1)   /* File not found */
47
#define TFTP_ERR_ACCESS_VIOLATION   (2)   /* Access violation */
48
#define TFTP_ERR_DISK_FULL          (3)   /* Disk full or allocation exceeded */
49
#define TFTP_ERR_ILLEGAL_OPERATION  (4)   /* Illegal TFTP operation */
50
#define TFTP_ERR_UNKNOWN_ID         (5)   /* Unknown transfer ID */
51
#define TFTP_ERR_FILE_EXISTS        (6)   /* File already exists */
52
#define TFTP_ERR_NO_USER            (7)   /* No such user */
53
 
54
/* Custom TFTP protocol error codes */
55
#define TFTP_NO_ERROR     (-1)
56
#define TFTP_ERR_TIMEOUT  (-2)
57
 
58
/* TFTP connection modes */
59
#define TFTP_NETASCII_MODE  "netascii"
60
#define TFTP_OCTET_MODE     "octet"
61
#define TFTP_MAIL_MODE      "mail"
62
 
63
/* Status */
64
#define TFTP_NOT_CONNECTED          (-1)
65
#define TFTP_OPEN                   (-2)
66
#define TFTP_ACTIVE                 (-3)
67
#define TFTP_CONNECTION_REQUESTING  (-4)
68
#define TFTP_STREAMING              (-5)
69
#define TFTP_FLUSHING               (-6)
70
#define TFTP_ERR                    (-100)
71
 
72
/* Mode options */
73
//#define TFTP_UPLOAD           (1)
74
//#define TFTP_DOWNLOAD (2)
75
 
76
/* Closing options */
77
#define TFTP_STOP_NOW                   (1)
78
#define TFTP_FLUSH_BUFFER       (2)
79
 
80
/* Base port address for socket communication */
81
#define BASE_PORT                       (2000)
82
 
83
/* The standard size of the tftp data packet */
84
#define TFTP_DATA_SIZE  (512)
85
 
86
typedef struct tftp_packet {
87
  WORD opcode;                        /* This is the opcode that represents operation to perform. */
88
  union {
89
    struct {
90
      BYTE filename[TFTP_DATA_SIZE];  /* This is the download data. */
91
    } request;
92
    struct {
93
      WORD block;                     /* The number of this block. */
94
      BYTE data[TFTP_DATA_SIZE];      /* This is the download data. */
95
    } data;
96
    struct {
97
      WORD block;                     /* This is the block number of the last data packet received. */
98
    } ack;
99
    struct {
100
      WORD errcode;                   /* This is the error code from the TFTP server. */
101
      BYTE errmsg[TFTP_DATA_SIZE];    /* This is the error message from the server. */
102
    } err;
103
  } u;
104
} TFTP_PACKET;
105
 
106
#define MAX_CONCURRENT_STREAM                           (5)
107
#define MAX_BUFFER_SIZE                                                 (1000000)
108
#define TFTP_DEFAULT_TIMEOUT        (6000000)
109
#define TFTP_DEFAULT_TIMEOUT_NUMBER (5)
110
 
111
typedef struct tftp_model {
112
  int status;
113
  int errcode;
114
  char errmsg[200];
115
  int handle;
116
  BYTE filename[80];
117
  PID sender_pid;
118
  PID receiver_pid;
119
  int socket;
120
  UDP_ADDR host;
121
  UDP_ADDR local;
122
  unsigned int nblock;
123
  TFTP_PACKET last_sent;
124
  BYTE waiting_ack;
125
  TIME timestamp;   /* the time we sent the last packet (data or ack) */
126
  TIME timeout;     /* in microseconds */
127
  int ntimeout;     /* number of timeouts (when 0 -> error!) */
128
} TFTP_MODEL;
129
 
130
typedef struct tftp_buffer {
131
  BYTE *data;
132
  unsigned long size;
133
  unsigned long nbytes;
134
} TFTP_BUFFER;
135
 
136
/* Mutex constant */
137
#define TFTP_PI   (0)
138
#define TFTP_SRP  (1)
139
#define TFTP_PC   (2)
140
 
141
/* We need to know what kind of mutex the user wants to use to share data with the reading (writing) queue
142
 */
143
typedef struct tftp_mutex {
144
  BYTE semtype;                                 /* Semaphore type. */
145
  union {
146
    struct {                                            /* SRP */
147
      SRP_RES_MODEL r;
148
                        int pLevel;                             /* Preemption level */
149
    } srp;
150
    struct {                                            /* Priority ceiling */
151
      PC_RES_MODEL r;
152
                        int tPr;                                        /* Task priority */
153
    } pc;
154
    struct {                                            /* Priority inheritance */
155
      PI_mutexattr_t a;
156
    } pi;
157
  } sem;
158
} TFTP_MUTEX;
159
 
160
/***** Tftp packet related routines *****/
161
int tftp_get_opcode(TFTP_PACKET *pkt);
162
WORD tftp_get_data(TFTP_PACKET *pkt, BYTE *data, int n);
163
int tftp_get_ack_block(TFTP_PACKET *pkt);
164
int tftp_get_error(TFTP_PACKET *pkt, char *errmsg);
165
int tftp_fill_request(TFTP_PACKET *pkt, WORD opcode, const BYTE *filename, const BYTE *mode);
166
int tftp_fill_data(TFTP_PACKET *pkt, WORD nblock, BYTE *rawdata, WORD datasize);
167
int tftp_fill_ack(TFTP_PACKET *pkt, WORD nblock);
168
 
169
/***** Initialization routines *****/
170
int tftp_init();
171
int tftp_net_start(char *local_ip, char *host_ip, int init_net);
172
 
173
/***** Parameter setting routines *****/
174
int tftp_set_timeout(int h, int sec);
175
int tftp_set_timeout_numbers(int h, int n);
176
 
177
/***** Connection routines *****/
178
int tftp_open(char *fname);
179
int tftp_upload(int i, unsigned long buffsize, sem_t *mtx);
180
int tftp_download(int i, unsigned long buffsize, sem_t *mtx);
181
int tftp_close(int h, int hardness);
182
 
183
/* Buffer I/O routines */
184
int tftp_put(int h, BYTE *rawdata, WORD n);
185
int tftp_get(int h, BYTE *rawdata, WORD n);
186
int tftp_getbuffersize(int h);
187
int tftp_usedbuffer(int h);
188
int tftp_freebuffer(int h);
189
 
190
int tftp_status(int h);
191
 
192
/* Debugger routines */
193
int debug_setbuffer(int h, int size);
194
void debug_freebuffer(int h);
195
 
196
#endif  /* tftp.h */