1 /*
2  * ftypes.h
3  *
4  * $Id: ftypes.h,v 1.1 2006/02/13 09:58:08 andrzej Exp $
5  *
6  * Redboot Flash Configuration parser.
7  * Argument parsers - header.
8  *
9  * Copyright (C) 2006 Ekiert sp z o.o.
10  * Author: Andrzej Ekiert <a.ekiert@ekiert.com>
11  *
12  * This program is free software; you can redistribute it and/or
13  * modify it under the terms of the GNU General Public License
14  * as published by the Free Software Foundation; either version
15  * 2 of the License, or (at your option) any later version.
16  */
17 
18 #ifndef FTYPES_H
19 #define FTYPES_H
20 
21 typedef int8_t (*parser_t)(uint8_t *text, void *buf);
22 typedef void (*printer_t)(void *buf);
23 
24 /*
25  * This is very unfortunate that RedBoot authors didn't encode these
26  * constants in the configuration structure.
27  */
28 //CYGNUM_REDBOOT_FLASH_SCRIPT_SIZE
29 #define MAX_SCRIPT_LENGTH 512
30 
31 //CYGNUM_REDBOOT_FLASH_STRING_SIZE
32 #define MAX_STRING_LENGTH 128
33 
34 //CYGNUM_REDBOOT_FLASH_CONFIG_SIZE
35 #define MAX_CONFIG_DATA 4096
36 
37 /*
38  * RedBoot flash configuration type description.
type_prio(enum ice_cand_type type)39  */
40 #define MAX_TYPE_NAME 16
41 #define MAX_TYPE_SIZE MAX_CONFIG_DATA
42 typedef struct {
43 	uint8_t type_name[MAX_TYPE_NAME];
44 	int16_t type_size;
45 	parser_t parser;
46 	printer_t printer;
47 } type_t;
48 
49 #define NUM_TYPES 8
50 extern type_t types[NUM_TYPES];
51 
ice_cand_calc_prio(enum ice_cand_type type,uint16_t local,unsigned compid)52 /*
53  * 'data type' field encoding
54  */
55 #define CONFIG_EMPTY   0
56 #define CONFIG_BOOL    1
57 #define CONFIG_INT     2
58 #define CONFIG_STRING  3
59 #define CONFIG_SCRIPT  4
60 #define CONFIG_IP      5
61 #define CONFIG_ESA     6
62 #define CONFIG_NETPORT 7
63 
64 /*
65  * Size assumptions (may not be valid for all platforms!):
66  *  - bool: assuming 4 bytes (might be 2)
67  *  - int: assuming 4 bytes (might be 2)
68  *  MAX_STRING_LENGTH and MAX_SCRIPT_LENGTH depend on RedBoot configuration
69  *  and are not encoded anywhere within the structure.
70  */
71 #define SIZE_EMPTY 0
72 #define SIZE_BOOL 4
73 #define SIZE_INT 4
74 #define SIZE_STRING MAX_STRING_LENGTH
75 #define SIZE_SCRIPT MAX_SCRIPT_LENGTH
76 #define SIZE_IP 4
77 #define SIZE_ESA 8
78 #define SIZE_NETPORT MAX_STRING_LENGTH
79 
80 #define TYPE_NAME(index) (types[index].type_name)
81 #define TYPE_SIZE(index) (types[index].type_size)
82 #define TYPE_PARSER(index) (types[index].parser)
83 #define TYPE_PRINTER(index) (types[index].printer)
84 
85 int8_t verify_ftype(uint8_t type);
86 
87 int8_t parse_bool(uint8_t *text, void *buf);
88 int8_t parse_int(uint8_t *text, void *buf);
89 int8_t parse_script(uint8_t *text, void *buf);
90 int8_t parse_string(uint8_t *text, void *buf);
91 int8_t parse_ip(uint8_t *text, void *buf);
92 int8_t parse_esa(uint8_t *text, void *buf);
93 int8_t parse_netport(uint8_t *text, void *buf);
94 
95 void print_bool(void *buf);
96 void print_int(void *buf);
97 void print_string(void *buf);
98 void print_script(void *buf);
99 void print_ip(void *buf);
100 void print_esa(void *buf);
101 void print_netport(void *buf);
102 
103 #endif //FTYPES_H
104 
105