forked from ap51-flash/ap51-flash
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproto.h
104 lines (89 loc) · 2.55 KB
/
proto.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/*
* Copyright (C) Marek Lindner
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of version 3 of the GNU General Public
* License as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301, USA
*
* SPDX-License-Identifier: GPL-3.0+
* License-Filename: LICENSES/preferred/GPL-3.0
*/
#ifndef __AP51_FLASH_PROTO_H__
#define __AP51_FLASH_PROTO_H__
#include <stdint.h>
#include <stdio.h>
#include <string.h>
struct node;
#define NET_IP_ALIGN 2
enum tcp_status {
TCP_STATUS_SYN_SENT,
TCP_STATUS_ESTABLISHED,
TCP_STATUS_TELNET_READY,
};
struct tcp_state {
char *packet_buff;
enum tcp_status status;
unsigned int his_seq;
unsigned int his_ack_seq;
unsigned int his_last_len;
unsigned int my_seq;
unsigned int my_ack_seq;
};
struct image_state {
int fd;
unsigned int bytes_sent;
unsigned int file_size;
unsigned int total_bytes_sent;
unsigned int flash_size;
unsigned int offset;
unsigned short last_packet_size;
unsigned short block_acked;
unsigned short block_sent;
/* flags */
unsigned char count_globally:1;
};
int arp_req_send(const uint8_t *src_mac, const uint8_t *dst_mac,
unsigned int src_ip, unsigned int dst_ip);
int tftp_init_upload(struct node *node);
int netconsole_init_upload(struct node *node);
void telnet_handle_connection(struct node *node);
int telnet_send_cmd(struct node *node, const char *cmd);
void handle_eth_packet(char *packet_buff, int packet_buff_len);
int proto_init(void);
void proto_free(void);
static inline void store_ip_addr(void *dst, uint32_t ip)
{
memcpy(dst, &ip, sizeof(ip));
}
static inline uint32_t load_ip_addr(void *src)
{
uint32_t ip;
memcpy(&ip, src, sizeof(ip));
return ip;
}
#if defined(DEBUG)
static inline int len_check(int buff_len, int req_len, char *desc)
#else
static inline int len_check(int buff_len, int req_len,
char (*desc)__attribute__((unused)))
#endif
{
if (buff_len >= req_len)
return 1;
#if defined(DEBUG)
fprintf(stderr, "Warning - dropping received %s packet as it is smaller than expected: %i (required: %i)\n",
desc, buff_len, req_len);
#endif
return 0;
}
#endif /* __AP51_FLASH_PROTO_H__ */