NetBurner 3.5.0
PDF Version
 
SSH/SecureSerToEthFactoryApp/src/serialburnerdata.h
1/*NB_REVISION*/
2
3/*NB_COPYRIGHT*/
4
5#ifndef _SERIALBURNERDATA_H_
6#define _SERIALBURNERDATA_H_
7
8/*
9 ******************************************************************************
10 *
11 * Include Files
12 *
13 ******************************************************************************
14 */
15#include <snmp.h>
16#include <netbios.h>
17#include <config_obj.h>
18#include <netinterface.h>
19#include <fdprintf.h>
20#include "nbfactory.h"
21#include "serialburnerdata.h"
22
23/*
24 ******************************************************************************
25 *
26 * Definitions
27 *
28 ******************************************************************************
29 */
30/* Constants that go with Protocol and selection list ProtocolList */
31#define PROTOCOL_UDP_TO_SERIAL "UDP"
32#define PROTOCOL_TCP_SSL_TO_SERIAL "TCP/SSL"
33#define PROTOCOL_TCP_TO_SERIAL "TCP"
34#define PROTOCOL_SSH "SSH"
35
36/* Constants that go with SerialMode and selection list SerialModeList */
37#define SERIAL_MODE_RS232 "RS-232"
38#define SERIAL_MODE_DEBUG "DEBUG"
39#define SERIAL_MODE_485H "RS-485 Half Duplex"
40#define SERIAL_MODE_485F "RS-485 Full Duplex"
41#define SERIAL_MODE_422F "RS-422 Full Duplex"
42#define SERIAL_MODE_485H_ECHO "RS-485 Half Duplex with Echo" // Used by PK70 quad UART blade board - S/W configurable
43#define SERIAL_MODE_485H_NOECHO "RS-485 Half Duplex without Echo" // Used by PK70 quad UART blade board - S/W configurable
44#define SERIAL_MODE_DISABLED "Disabled"
45
46#define SERIAL_MODE_DISABLED_PINS_OUTPUT_HIGH "Output High"
47#define SERIAL_MODE_DISABLED_PINS_OUTPUT_LOW "Output Low"
48#define SERIAL_MODE_DISABLED_PINS_HIZ "High Impedance"
49
50/* Constants that go with serial FlowMode and selection list FlowModeList */
51#define SERIAL_FLOW_MODE_NONE "None"
52#define SERIAL_FLOW_MODE_XON_OFF "XON/XOFF"
53#define SERIAL_FLOW_MODE_RTS_CTS "RTS/CTS"
54
55/* Constants that go with serial ConnectMode */
56#define SERIAL_CONNECT_CONNECT_NEVER "Never"
57#define SERIAL_CONNECT_CONNECT_AT_POWERUP "On power-up"
58#define SERIAL_CONNECT_CONNECT_WHEN_DATARX "If serial data received"
59
60/* Constants that go with IP_Addr_mode */
61/* These strings need to match the string defined in the ip4.mode config_chooser variable defined in the InterfaceBlock */
62#define IP_ADDR_MODE_DHCP "DHCP"
63#define IP_ADDR_MODE_DHCP_W_FALLBACK "DHCP w Fallback"
64#define IP_ADDR_MODE_STATIC "Static"
65#define IP_ADDR_MODE_DISABLED "Disabled"
66
67/* Constants that go with character strings */
68#define CONNECT_NAME_LENGTH (79)
69#define CONNECT_MESSAGE_LENGTH (79)
70#define CONNECT_LOSS_MESSAGE_LENGTH (79)
71#define DEVICE_NAME_LENGTH (15)
72#define NTP_NAME_LENGTH (35)
73#define USERNAME_LENGTH (39)
74#define PASSWORD_LENGTH (39)
75#define MAX_NUMERICAL_USER_INPUT_LENTH (32)
76#define MAX_STRING_USER_INPUT_LENTH (64)
77
78/* Constants that define buffer sizes */
79#define MAX_UDP_RX_BUFFER (1500)
80#define BUFFER_SIZE (20000)
81
82/* Constants that define task priorities */
83#define LED_TASK_PRIO (MAIN_PRIO - 1)
84#define SNMP_PRIO (MAIN_PRIO - 2)
85#define AT_COM_PRIO (MAIN_PRIO - 3)
86#define I2C_SERVER_TASK_PRIO (MAIN_PRIO + 1)
87#define GPIO_SERVER_TASK_PRIO (MAIN_PRIO + 2)
88#define START_WIFI_TASK_PRIO (OS_MAX_PRIOS - 2)
89
90#ifdef NB_FACTORY_INCLUDE_SSH
91
92/* Constants that go with SSH character strings */
93#define SSH_USERNAME_LENGTH (39)
94#define SSH_PASSWORD_LENGTH (39)
95
96#endif /* #ifdef NB_FACTORY_INCLUDE_SSH */
97
98extern MonitorRecord monitor_config;
99
100#ifdef NB_FACTORY_INCLUDE_SSL
101
102/*
103 ******************************************************************************
104 * Key or certificate size
105 * SSL Certificate size 2200 (empirical)
106 * OpenSSL format is Privacy-enhanced Electronic Mail (PEM) encoded
107 * NULL terminated for conversion
108 *
109 ******************************************************************************
110 */
111#define SERIAL_BURNER_CERTIFICATE_SIZE_MAX ((2 * 1024) - 1)
112#define SERIAL_BURNER_CERTIFICATE_SIZE_MAX_PEM ((3 * 1024) - 1)
113
114#endif /* #ifdef NB_FACTORY_INCLUDE_SSL */
115
116#if defined(NB_FACTORY_INCLUDE_SSH) || defined(NB_FACTORY_INCLUDE_SSL)
117
118/* Certificate and key status */
119#define SERIAL_BURNER_LIBRARY_DEFAULT ((uint8_t)0x00)
120#define SERIAL_BURNER_DEFAULT ((uint8_t)0x01)
121#define SERIAL_BURNER_USER_INSTALLED ((uint8_t)0x02)
122
123/*
124 ******************************************************************************
125 * Key size
126 * SSH MAX_PRIVKEY_SIZE 1700 (options.h)
127 * SSH key size (PEM) < 4K (empirical)
128 * NULL terminated for conversion
129 *
130 ******************************************************************************
131 */
132#define SERIAL_BURNER_KEY_SIZE_MAX_PEM ((4 * 1024) - 1)
133
134#endif /* #if defined(NB_FACTORY_INCLUDE_SSH) || defined(NB_FACTORY_INCLUDE_SSL) */
135/*
136 ******************************************************************************
137 * HTML support
138 ******************************************************************************
139 */
140/* HTML data sizes */
141#define SERIAL_BURNER_HTML_INPUT_NUMBER_SIZE (5)
142
143/* HTML data sizes */
144#define SERIAL_BURNER_HTML_HEX_NUMBER_LENGTH (2)
145
146/* The following defines the webpage table width in percentage of the column that
147 * includes text description of each input field. It allows platforms with two
148 * ports or less to use more of the table width to fit text, improving readability.
149 */
150#if ((NB_FACTORY_SERIAL_PORTS + NB_FACTORY_I2C_PORTS) <= 2)
151#define SERIAL_BURNER_DESCRIPTION_COLUMN_WIDTH_PERCENT (40)
152#else
153#define SERIAL_BURNER_DESCRIPTION_COLUMN_WIDTH_PERCENT (30)
154#endif
155
156#define SERIAL_BURNER_PORT_COLUMN_WIDTH_PERCENT ((100 - SERIAL_BURNER_DESCRIPTION_COLUMN_WIDTH_PERCENT) / (NB_FACTORY_SERIAL_PORTS + NB_FACTORY_I2C_PORTS))
157
158/* HTML I2C column width percentage */
159#define SERIAL_BURNER_HTML_I2C_WIDTH (70)
160
161/* HTML input name maximum size */
162#define SERIAL_BURNER_HTML_INPUT_SIZE (39)
163
164/* HTML IP address string size */
165#define SERIAL_BURNER_HTML_IP_STRING_SIZE (20)
166
167/* Password protection string (SSH_PASSWORD_LENGTH length ) */
168#define SERIAL_BURNER_PASSWORD_STRING "*******************"
169
170/*
171 ******************************************************************************
172 * Booting support
173 ******************************************************************************
174 */
175#define boot_iprintf(...) \
176 { \
177 if (monitor_config.Quiet == 0) \
178 { \
179 int ifNum = GetFirstInterface(); \
180 InterfaceBlock *pIfB = GetInterfaceBlock(ifNum); \
181 if (pIfB != nullptr) \
182 { \
183 iprintf("%s : ", pIfB->device_name.c_str()); \
184 iprintf(__VA_ARGS__); \
185 iprintf("\r\n"); \
186 } \
187 } \
188 }
189
190/*
191 ******************************************************************************
192 * Debug support
193 ******************************************************************************
194 */
195#define debug_iprintf(...) \
196 { \
197 if (bShowDebug == true) \
198 { \
199 int ifNum = GetFirstInterface(); \
200 InterfaceBlock *pIfB = GetInterfaceBlock(ifNum); \
201 if (pIfB != nullptr) \
202 { \
203 iprintf("%s [debug] : ", pIfB->device_name.c_str()); \
204 iprintf(__VA_ARGS__); \
205 iprintf("\r\n"); \
206 } \
207 } \
208 }
209
210/*
211 ******************************************************************************
212 *
213 * Structures
214 *
215 ******************************************************************************
216 */
217// #ifndef SNMP
218// #include <snmp.h>
219// struct SysInfo
220// {
221// char SysContact[ 256 ];
222// char SysName[ 256 ];
223// char SysLocation[ 256 ];
224// unsigned char ReadCommunity[ 40 ];
225// unsigned char WriteCommunity[ 40 ];
226// IPADDR trap_destination;
227// uint32_t trap_enable_flags;
228// uint32_t valid;
229// };
230// #endif /* SNMP */
231
232#ifndef SNMP
233#include <snmp.h>
234class SysInfo : public config_obj
235{
236 public:
237 config_string SysContact{"", "Sys Contact"};
238 config_string SysName{"", "Sys Name"};
239 config_string SysLocation{"", "Sys Location"};
240 config_string ReadCommunity{"", "Read Community"};
241 config_string WriteCommunity{"", "Write Community"};
242 config_IPADDR4 trap_destination{"", "Trap Destination"};
243 config_uint trap_enable_flags{0, "Trap Enable Flags"};
244 config_uint valid{0, "Valid"};
245 ConfigEndMarker;
246
247 SysInfo(const char *name, const char *desc = nullptr) : config_obj(name, desc){};
248 SysInfo(config_obj &owner, const char *name, const char *desc = nullptr) : config_obj(owner, name, desc){};
249 SysInfo & operator=(const SysInfo & si)
250 {
251 SysContact = si.SysContact;
252 SysName = si.SysName;
253 SysLocation = si.SysLocation;
254 ReadCommunity = si.ReadCommunity;
255 WriteCommunity = si.WriteCommunity;
256 trap_destination = si.trap_destination;
257 trap_enable_flags = si.trap_enable_flags;
258 valid = si.valid;
259
260 return *this;
261 }
262};
263#endif /* SNMP */
264
265/*
266 Port Setting (Protocol)
267
268 * Listening socket (All) *
269 ListenPort - Listen port
270 InactivityTimeoutInSecs - Inactivity timeout in seconds
271 New_connection_timeout - Connection timeout
272 ConnectMode - Serial connect mode
273
274 * Connect on power-up and received serial data choices (TCP) *
275 ConnectPort - Port
276 ConnectName - Target name for GetHostByName
277 ConnectAddress - Target IP address
278 ConnectIdleTimeout - Idle timeout in seconds
279 Connection_retry_timeout- Retry interval in seconds
280 keepAliveInterval - Check and maintain the connection in second intervals
281
282 * Primary connection settings - serial port settings (All) *
283 SerialMode - Type port
284 DataBaudRate - Baud rate
285 Output_Bits - Data bits per byte
286 Output_Parity - Parity
287 Output_Stop - Stop bits
288 FlowMode - Flow control
289
290 * Primary connection settings - serial data notification settings (TCP, UDP) *
291 ConnectMessage - Serial message upon connection
292 ConnectLossMessage - Serial message upon connection loss
293 BreakOnConnect - Send serial break on connection
294 BreakInterval - Break interval
295 BreakKeyFlag - Send data then a break
296 BreakKeyValue - Data prior to break
297
298 * UDP *
299 UdpAccumulatedChars - Char. to accumulate before sending packet
300 UdpWait - Accumulation wait in ticks
301 UdpTriggerChar - Flushing character
302 bLearnUdp - Learn IP address from connection
303 bUdpCheckFramingChar - UDP framing character to check
304
305 * Custom Framing (TCP, SSH) *
306 bTcpCustomFrame - Enabled?
307 TcpAccumulatedChars - Char. to accumulate before sending packet
308 TcpWait - Accumulation wait in ticks
309 TcpTriggerChar - Serial flushing character
310
311 * Framing (TCP) *
312 bTcpCheckFramingChar - TCP framing character to check
313
314*/
315class NV_OnePortSetting : public config_obj
316{
317 public:
318 config_uint ListenPort{NB_FACTORY_LISTEN_PORT_DEFAULT, "Listen Port"};
319 config_uint InactivityTimeoutInSecs{NB_FACTORY_INACTIVITY_TIMEOUT_DEFAULT, "Inactivity Timeout(seconds)"};
320 config_uint New_connection_timeout{NB_FACTORY_NEW_CONNECTION_TIMEOUT_DEFAULT, "New Connection Timeout(seconds)"};
321 config_chooser ConnectMode{"Connect Mode", "Never", "Never,On power-up,If serial data received"};
322 config_uint ConnectPort{NB_FACTORY_CONNECT_PORT_DEFAULT, "Connect Port"};
323 config_string ConnectName1{"", "Connect Name 1"};
324 config_string ConnectName2{"", "Connect Name 2"};
325 config_IPADDR4 ConnectAddress1{"0.0.0.0", "Connect Address 1"};
326 config_IPADDR4 ConnectAddress2{"0.0.0.0", "Connect Address 2"};
327 config_uint ConnectIdleTimeout{NB_CONNECT_IDLE_TIMEOUT_DEFAULT, "Connect Idle Timeout(seconds)"};
328 config_uint Connection_retry_timeout{NB_CONNECT_RETRY_TIMEOUT_DEFAULT, "Connection Retry Timeout(seconds)"};
329 config_uint keepAliveInterval{NB_CONENCT_KEEP_ALIVE_INTERVAL_DEFAULT, "Keep Alive Interval(seconds)"};
330 // Port-TODO: Hook in system serial port configurations so that any change made in the Factory App also change the system's serial port
331 // config variable.
332 config_chooser SerialMode{"Serial Mode", NB_FACTORY_DEFAULT_SERIAL_MODE, NB_FACTORY_SERIAL_CAPABILITY_RS232};
333 config_chooser DataBaudRate{
334 "Data Baud Rate", NB_FACTORY_SERIAL_DATA_RATE_DEFAULT,
335 "921600,500000,460800,345600,256000,230400,128000,115200,57600,38400,32000,19200,9600,4800,2400,1200,Custom"};
336 config_uint CustomBaudRate{NB_FACTORY_SERIAL_CUSTOM_DATA_RATE_DEFAULT, "Custom Baudrate"};
337 config_chooser Output_Bits{"Output Bits", NB_FACTORY_SERIAL_DATA_BITS_DEFAULT, "8,7,6,5"};
338 config_chooser Output_Parity{"Output Parity", NB_FACTORY_SERIAL_PARITY_DEFAULT, "None,Odd,Even"};
339 config_chooser Output_Stop{"Output Stop", NB_FACTORY_SERIAL_STOP_BITS_DEFAULT, "1,2"};
340 config_chooser FlowMode{"Flow Control Mode", NB_FACTORY_SERIAL_FLOW_CONTROL_DEFAULT, "None,XON/XOFF,RTS/CTS"};
341 config_bool bDoAtCommand{NB_FACTORY_DO_AT_COMMANDS_DEFAULT, "Do AT Commands"};
342 config_chooser DisabledPortPinFunction{"Disabled Port Pin Function", NB_FACTORY_DISABLED_SER_PORT_PIN_FUNC_DEFAULT, "Output High,Output Low,High Impedance"};
343 config_string ConnectMessage{"", "Connect Message"};
344 config_bool bUseConnectMessage{NB_FACTORY_USE_CONNECT_MSG_DEFAULT, "Use the Configured Connect Message"};
345 config_string ConnectLossMessage{"", "Lost Connection Message"};
346 config_bool bUseConnectLossMessage{NB_FACTORY_USE_CONNECTION_LOST_MSG_DEFAULT, "Use the Configured Lost Connection Message"};
347 config_bool BreakOnConnect{NB_FACTORY_BREAK_ON_CONNECT_DEFAULT, "Break On Connect"};
348 config_uint BreakInterval{NB_FACTORY_BREAK_INTERVAL_DEFAULT, "Break Interval"};
349 config_bool BreakKeyFlag{NB_FACTORY_BREAK_KEY_FLAG_DEFAULT, "Break Key Flag"};
350 config_string BreakKeyValue{NB_FACTORY_BREAK_KEY_VALUE_DEFAULT, "Break Key Value"};
351 config_uint UdpAccumulatedChars{NB_FACTORY_ACCUMULATED_CHARS_UDP_DEFAULT, "UDP Accumulated Chars"};
352 config_uint UdpWait{NB_FACTORY_WAIT_UDP_IN_TICKS_DEFAULT, "UDP Wait(ticks)"};
353 config_uint TcpAccumulatedChars{NB_FACTORY_ACCUMULATED_CHARS_TCP_DEFAULT, "TCP Accumulated Chars"};
354 config_uint TcpWait{NB_FACTORY_WAIT_TCP_IN_TICKS_DEFAULT, "TCP Wait(ticks)"};
355 config_string UdpTriggerChar{NB_FACTORY_TRIGGER_CHAR_UDP_DEFAULT,
356 "UDP Trigger Character"};
357 config_string TcpTriggerChar{NB_FACTORY_TRIGGER_CHAR_TCP_DEFAULT,
358 "TCP Trigger Character"}; // Port-TODO: need to test char to config_uint comparison when parsing
359 config_bool bListenForTCPConnections{NB_FACTORY_LISTEN_FOR_TCP_CONNECT_DEFAULT, "Listen for incoming network connections"};
360 config_bool bTcpCustomFrame{NB_FACTORY_CUSTOM_FRAME_TCP_DEFAULT, "TCP Custom Frame"};
361 config_bool bLearnUdp{NB_FACTORY_LEARN_UDP_DEFAULT, "Learn UDP"};
362 config_bool bUdpCheckFramingChar{NB_FACTORY_CHECK_FRAMING_CHAR_UDP_DEFAULT, "Check UDP Framing Character"};
363 config_bool bTcpCheckFramingChar{NB_FACTORY_CHECK_FRAMING_CHAR_TCP_DEFAULT, "Check TCP Framing Character"};
364 config_bool bAlwaysStoreSerialChars{false, "Always Store Serial Characters"};
365#ifdef SB800EX
366 config_bool bDTRReflectsConnection{false, "DTR Reflects Connection"}; // Port-TODO: requires logic based on port number to initialize. See setDefaultsForUDP()
367#endif /* SB800EX */
368 config_bool bTCPasSSL{false, "Allow SSL on TCP Socket"};
369 ConfigEndMarker;
370
371 NV_OnePortSetting(const char *name,
372 const char *desc = nullptr,
373 const char *serialMode = nullptr,
374 const char *serialModeChoices = nullptr)
375 : config_obj(name, desc)
376 {
377 if (serialModeChoices != nullptr) { SerialMode.SetChoices(serialModeChoices); }
378 if (serialMode != nullptr)
379 {
380 SerialMode = serialMode;
381
382 if (strncmp(serialMode, SERIAL_MODE_DEBUG, sizeof(SERIAL_MODE_DEBUG)) == 0)
383 {
384 // Disable AT command parser on a debug serial port
385 bDoAtCommand = false;
386 }
387 }
388 };
389
390 NV_OnePortSetting(config_obj &owner,
391 const char *name,
392 const char *desc = nullptr,
393 const char *serialMode = nullptr,
394 const char *serialModeChoices = nullptr)
395 : config_obj(owner, name, desc)
396 {
397 if (serialModeChoices != nullptr) { SerialMode.SetChoices(serialModeChoices); }
398 if (serialMode != nullptr)
399 {
400 SerialMode = serialMode;
401
402 if (strncmp(serialMode, SERIAL_MODE_DEBUG, sizeof(SERIAL_MODE_DEBUG)) == 0)
403 {
404 // Disable AT command parser on a debug serial port
405 bDoAtCommand = false;
406 }
407 }
408 };
409};
410
411/* ic - The byte value written to the I2FDR register of the processor
412 * to reach a desired frequency divider. Used with InitI2C() to
413 * initialize the bus to a particular I2C bus speed
414 * FreqDivider - The frequency divider that corresponds to the byte value in ic.
415 * For a table of ic-frequency divider pairs, refer to the reference manual for the
416 * processor - specifically, refer to the I2FDR section of the
417 * I2C chapter.
418 */
419class NV_OneI2CPortSetting : public config_obj
420{
421 public:
422 // I2C parameters
423 config_uint ic{NB_FACTORY_I2C_IC_DEFAULT, "ic"};
424 config_uint FreqDivider{NB_FACTORY_I2C_FREQ_DIVIDER_DEFAULT, "Frequency Divider"};
425 config_uint CustomBaudRate{0, "Custom Baud Rate"};
426 config_uint BusSpeed{100000, "I2C Bus Speed"};
427 config_uint SetMasterAddress{NB_FACTORY_I2C_ADDRESS_DEFAULT, "Set Master Address"};
428 config_uint SaveMasterAddress{NB_FACTORY_I2C_ADDRESS_DEFAULT, "Save Master Address"};
429
430 // TCP parameters
431 config_uint ListenPort{NB_FACTORY_I2C_LISTEN_PORT_DEFAULT, "Listen Port"};
432 config_bool bListenCheck{NB_FACTORY_LISTEN_FOR_TCP_CONNECT_DEFAULT, "Listen for incoming network connections"};
433 config_uint InactivityTimeoutInSecs{NB_FACTORY_INACTIVITY_TIMEOUT_DEFAULT, "Inactivity Timeout(seconds)"};
434 config_uint New_connection_timeout{NB_FACTORY_NEW_CONNECTION_TIMEOUT_DEFAULT, "New Connection Timeout(seconds)"};
435 config_uint ConnectIdleTimeout{NB_CONNECT_IDLE_TIMEOUT_DEFAULT, "Connect Idle Timeout(seconds)"};
436 config_bool bTCPasSSL{false, "Allow TCP as SSL"};
437 ConfigEndMarker;
438
439 NV_OneI2CPortSetting(const char *name, const char *desc = nullptr) : config_obj(name, desc){};
440 NV_OneI2CPortSetting(config_obj &owner, const char *name, const char *desc = nullptr) : config_obj(owner, name, desc){};
441};
442
443/* Refer to the I2FDR section of the reference manual for the processor in use
444 * for a table of dividers and the respective ICs's */
445struct BaudRate
446{
447 unsigned char ic;
448 int divider;
449};
450
451
452extern const char* defaultSerialPortModes[];
453
454class NV_SettingsStruct : public config_obj
455{
456 public:
457 /* NetBurner protocol */
458 config_chooser Protocol{"Protocol", "TCP/SSL", "UDP,TCP/SSL,SSH,TCP"};
459 config_chooser ConnectMode{"Connect Mode", "Never", "Never,On power-up,If serial data received"};
460
461 /* NetBurner address configuration */
462 config_string NTPName{NB_FACTORY_NTPSERVERNAME_DEFAULT, "NTP Name"}; // NTPName[ NTP_NAME_LENGTH+ 1 ];
463 config_IPADDR4 NTP_Addr{"0.0.0.0", "NTP IPv4 Address"};
464
465 NV_OnePortSetting port0{"Serial Port 0", nullptr, defaultSerialPortModes[0], NB_FACTORY_SERIAL_PORT_0_MODE_CAPABILITY};
466#if !(defined SOMRT1061)
467 NV_OnePortSetting port1{"Serial Port 1", nullptr, defaultSerialPortModes[1], NB_FACTORY_SERIAL_PORT_1_MODE_CAPABILITY};
468#endif
469
470#if (defined NANO54415)
471 NV_OnePortSetting port2{"Serial Port 2", nullptr, defaultSerialPortModes[2], NB_FACTORY_SERIAL_PORT_2_MODE_CAPABILITY};
472 NV_OnePortSetting port3{"Serial Port 3", nullptr, defaultSerialPortModes[3], NB_FACTORY_SERIAL_PORT_3_MODE_CAPABILITY};
473 NV_OnePortSetting port4{"Serial Port 4", nullptr, defaultSerialPortModes[4], NB_FACTORY_SERIAL_PORT_4_MODE_CAPABILITY};
474#elif ((defined MODM7AE70 && defined USE_E70_UART_SERIAL_PORTS))
475 NV_OnePortSetting port2{"Serial Port 2", nullptr, defaultSerialPortModes[2], NB_FACTORY_SERIAL_PORT_2_MODE_CAPABILITY};
476 NV_OnePortSetting port3{"Serial Port 3", nullptr, defaultSerialPortModes[3], NB_FACTORY_SERIAL_PORT_3_MODE_CAPABILITY};
477 NV_OnePortSetting port4{"Serial Port 4", nullptr, defaultSerialPortModes[4], NB_FACTORY_SERIAL_PORT_4_MODE_CAPABILITY};
478 NV_OnePortSetting port5{"Serial Port 5", nullptr, defaultSerialPortModes[5], NB_FACTORY_SERIAL_PORT_5_MODE_CAPABILITY};
479 NV_OnePortSetting port6{"Serial Port 6", nullptr, defaultSerialPortModes[6], NB_FACTORY_SERIAL_PORT_6_MODE_CAPABILITY};
480#elif ( defined SOMRT1061 )
481 NV_OnePortSetting port1{"Serial Port 1", nullptr, defaultSerialPortModes[1], NB_FACTORY_SERIAL_PORT_1_MODE_CAPABILITY};
482 NV_OnePortSetting port2{"Serial Port 2", nullptr, defaultSerialPortModes[2], NB_FACTORY_SERIAL_PORT_2_MODE_CAPABILITY};
483 NV_OnePortSetting port3{"Serial Port 3", nullptr, defaultSerialPortModes[3], NB_FACTORY_SERIAL_PORT_3_MODE_CAPABILITY};
484 NV_OnePortSetting port4{"Serial Port 4", nullptr, defaultSerialPortModes[4], NB_FACTORY_SERIAL_PORT_4_MODE_CAPABILITY};
485 NV_OnePortSetting port5{"Serial Port 5", nullptr, defaultSerialPortModes[5], NB_FACTORY_SERIAL_PORT_5_MODE_CAPABILITY};
486 NV_OnePortSetting port6{"Serial Port 6", nullptr, defaultSerialPortModes[6], NB_FACTORY_SERIAL_PORT_6_MODE_CAPABILITY};
487#endif
488
489#ifdef SUPPORTED_GPIO_SERVER_PLATFORM
490 config_bool bEnableGpioProcess{NB_FACTORY_DO_GPIO_COMMANDS_DEFAULT, "bEnableGpioProcess"};
491 config_bool bEnableHighDrive{NB_FACTORY_ENABLE_GPIO_HI_DRIVE_DEFAULT, "bEnableHighDrive"};
492 config_uint GpioProcessPort{NB_FACTORY_GPIO_PORT_DEFAULT, "GpioProcessPort"};
493 config_uint GpioInactivityTimeoutInSecs{NB_CONNECT_IDLE_TIMEOUT_DEFAULT, "Inactivity timeout in seconds"};
494 config_uint GpioMaxConnections{NB_MAX_TCP_CONNECTIONS, "Max simultaneous connections"};
495 config_bool bSaveGpioToFlash{
496 NB_FACTORY_GPIO_SAVE_TO_FLASH_DEFAULT,
497 "Save every change to a pin's setting/state to flash. This will use more flash write cycles if a pin is modified often."};
498#endif
499
500 SysInfo SysInfoData{"SNMP_SysInfo"};
501
502 /* I2C address */
503 config_string slaveI2CAddress{"", "I2C Slave Address"}; // char slaveI2CAddress[3];
504
505#if (defined SUPPORTED_I2C_PLATFORM)
506 NV_OneI2CPortSetting i2c_port{"I2C Configuration"};
507#endif
508
509#ifdef NB_FACTORY_INCLUDE_SSL
510
511 /* SSL certificate and keys file lengths */
512 config_uint SslCertificateSource{SERIAL_BURNER_LIBRARY_DEFAULT, "SSL Certificate Source"};
513 config_uint SslCertificateLength{0, "SSL Certificate Length"};
514 config_uint SslKeyLength{0, "SSL Key Length"};
515
516#endif /* #ifdef NB_FACTORY_INCLUDE_SSL */
517
518#ifdef NB_FACTORY_INCLUDE_SSH
519
520 /* SSH user name and password */
521 config_pass SshUserName{"", "SSH User Name"};
522 config_pass SshPassword{"", "SSH Password"};
523
524 /* SSH key source and lengths (default and user installed) */
525 config_uint SshKeyRsaSource{SERIAL_BURNER_LIBRARY_DEFAULT, "SSH Key RSA Source"};
526 config_uint SshKeyRsaLength{0, "SSH Key RSA Length"};
527 config_uint SshKeyEcdsaSource{SERIAL_BURNER_LIBRARY_DEFAULT, "SSH Key ECDSA Source"};
528 config_uint SshKeyEcdsaLength{0, "SSH Key ECDSA Length"};
529
530#endif /* #ifdef NB_FACTORY_INCLUDE_SSH */
531
532 config_bool bAllowAtToAccessAPassword{true, "Allow AT to Access A Password"};
533 config_bool bAllowAtToAccessSPassword{true, "Allow AT to Access S Password"};
534
535 /* Version verification key */
536 config_uint VerifyKey{NB_FACTORY_VERIFY_KEY, "App Version Verification Key"};
537
538 /* Flash File System Version verification key */
539 config_uint STDEFFSVerifyKey{STD_EFFS_VERIFY_KEY, "File System Version Verification Key"};
540
541 config_bool bFirstRun{true, "First time loading the SS2E Factory app on this device"};
542 ConfigEndMarker;
543
544 NV_OnePortSetting *ports[NB_FACTORY_SERIAL_PORTS];
545
546 NV_SettingsStruct(const char *name, const char *desc = nullptr, uint32_t configFlag = 0) : config_obj(name, desc)
547 {
548 if (configFlag > 0) { SetFlag(configFlag); }
549 // SetFlag(fConfigHidden); // hide from the config server
550
551 ports[0] = &port0;
552 ports[1] = &port1;
553
554#if (defined NANO54415)
555 ports[2] = &port2;
556 ports[3] = &port3;
557 ports[4] = &port4;
558#elif ((defined MODM7AE70 && defined USE_E70_UART_SERIAL_PORTS) || (defined SOMRT1061) )
559 ports[2] = &port2;
560 ports[3] = &port3;
561 ports[4] = &port4;
562 ports[5] = &port5;
563 ports[6] = &port6;
564#endif
565
566 #ifdef SB800EX
567 // SB800EX serial ports are numbered 1 and 2, not 0 and 1
568 ports[(int)(monitor_config.Uart) - 1]->SerialMode = SERIAL_MODE_DEBUG;
569 #else
570 ports[(int)(monitor_config.Uart)]->SerialMode = SERIAL_MODE_DEBUG;
571 #endif
572
573 for (uint8_t i = 1; i < NB_FACTORY_SERIAL_PORTS; i++)
574 {
575 // intentionally skip port 0 since it's initialized with a default value
576 ports[i]->ListenPort = ports[i]->ListenPort + i;
577 ports[i]->ConnectPort = ports[i]->ConnectPort + i;
578 }
579 };
580
581 NV_SettingsStruct(config_obj &owner, const char *name, const char *desc = nullptr, uint32_t configFlag = 0)
582 : config_obj(owner, name, desc)
583 {
584 if (configFlag > 0) { SetFlag(configFlag); }
585 // SetFlag(fConfigHidden);
586
587 ports[0] = &port0;
588 ports[1] = &port1;
589
590#if (defined NANO54415)
591 ports[2] = &port2;
592 ports[3] = &port3;
593 ports[4] = &port4;
594#elif ((defined MODM7AE70 && defined USE_E70_UART_SERIAL_PORTS) || (defined SOMRT1061) )
595 ports[2] = &port2;
596 ports[3] = &port3;
597 ports[4] = &port4;
598 ports[5] = &port5;
599 ports[6] = &port6;
600#endif
601
602 #ifdef SB800EX
603 // SB800EX serial ports are numbered 1 and 2, not 0 and 1
604 ports[(int)(monitor_config.Uart) - 1]->SerialMode = SERIAL_MODE_DEBUG;
605 #else
606 ports[(int)(monitor_config.Uart)]->SerialMode = SERIAL_MODE_DEBUG;
607 #endif
608
609 for (uint8_t i = 1; i < NB_FACTORY_SERIAL_PORTS; i++)
610 {
611 // intentionally skip port 0 since it's initialized with a default value
612 ports[i]->ListenPort = ports[i]->ListenPort + i;
613 ports[i]->ConnectPort = ports[i]->ConnectPort + i;
614 }
615 };
616};
617
618#ifdef SUPPORTED_GPIO_SERVER_PLATFORM
619#include <cpu_pins.h>
620#include <pins.h>
621#include <htmlfiles.h>
622class NV_PinIOConfig : public config_obj
623{
624 public:
625 config_chooser cc_pinFunction{"Function", "Not Configured", "Not Configured,GPIO Input,GPIO Output 0,GPIO Output 1"};
626 config_string cs_currentState{"Not Configured", "Current State"};
627
628 ConfigEndMarker;
629
630 typedef enum
631 {
632 PIN_FN_NO_CONFIG = 0,
633 PIN_FN_IN,
634 PIN_FN_OUT_0,
635 PIN_FN_OUT_1,
636 PIN_FN_A,
637 PIN_FN_B,
638 PIN_FN_C,
639 PIN_FN_D
640 } pin_fn_t;
641
642 uint8_t m_headerNum;
643 uint8_t m_pinNum;
644 uint32_t m_configFlags;
645 PinIO m_pinIO;
646
647 NV_PinIOConfig(const char *name,
648 PinIO pin,
649 const char *desc = nullptr,
650 uint8_t headerNumber = 0,
651 uint8_t pinNumber = 0,
652 const char *pinFuncSelection = nullptr,
653 const char *pinFunctionChoices = nullptr,
654 uint32_t configFlag = 0)
655 : m_pinIO(pin), config_obj(name, desc)
656 {
657 if (configFlag) { SetFlag(configFlag); }
658 if (pinFunctionChoices != nullptr) { cc_pinFunction.SetChoices(pinFunctionChoices); }
659 if (pinFuncSelection != nullptr) { cc_pinFunction = pinFuncSelection; }
660
661 m_headerNum = headerNumber;
662 m_pinNum = pinNumber;
663 m_configFlags = configFlag;
664
665 if (m_pinIO.mask == 0) // pin is not modifiable. Ex: GND, VCC, or not a valid header pin
666 {
667 SetFlag(fConfigReadOnly);
668 cc_pinFunction.SetChoices("Fixed");
669 cc_pinFunction = "Fixed";
670 }
671 }
672
673 NV_PinIOConfig(config_obj &owner,
674 const char *name,
675 PinIO pin,
676 const char *desc = nullptr,
677 uint8_t headerNumber = 0,
678 uint8_t pinNumber = 0,
679 const char *pinFuncSelection = nullptr,
680 const char *pinFunctionChoices = nullptr,
681 uint32_t configFlag = 0)
682 : m_pinIO(pin), config_obj(owner, name, desc)
683 {
684 if (configFlag > 0) { SetFlag(configFlag); }
685 if (pinFunctionChoices != nullptr) { cc_pinFunction.SetChoices(pinFunctionChoices); }
686 if (pinFuncSelection != nullptr) { cc_pinFunction = pinFuncSelection; }
687
688 m_headerNum = headerNumber;
689 m_pinNum = pinNumber;
690 m_configFlags = configFlag;
691
692 if (m_pinIO.mask == 0) // pin is not modifiable. Ex: GND, VCC, or not a valid header pin
693 {
694 SetFlag(fConfigReadOnly);
695 cc_pinFunction.SetChoices("Fixed");
696 cc_pinFunction = "Fixed";
697 }
698 }
699
700 /* It is assumed that a valid NV_PinIOConfig will have a name. An invalid
701 * NV_PinIOConfig, like an end marker, will have a nullptr name value */
702 inline bool valid() { return pName != nullptr; }
703
704 bool ConfigureFromPinIOFunction()
705 {
706 int8_t pin_fn = m_pinIO.getFn();
707 if (pin_fn < 0) { return false; }
708
709 // check if the pin has already been configured for a function other than GPIO
710 // if the PinIO is not configured for a peripheral function, allow it to be configured
711
712 // if the PinIO is already configured for a peripheral function, what should we do?
713 // option 1: don't allow it to be configured via the gpio webpage
714 // option 2: display which peripheral function (A,B,C,D) and allow it to be reconfigured for GPIO
715 }
716
717 void DisplayPinFunctionToWeb(int sock)
718 {
719 fdprintf(sock, "\r\n\t\t<td><font size=\"2\">");
720 WriteHtmlVariable(sock, ConfigRenderFunc(2, cc_pinFunction));
721 fdprintf(sock, "\r\n\t\t</font></td>\r\n");
722 }
723
724 void DisplayPinDriveToWeb(int sock)
725 {
726 if (!valid() || m_pinIO.mask == 0)
727 {
728 // The pin has not been initialized
729 cs_currentState = "N/A";
730 }
731 else
732 {
733 if (cc_pinFunction.IsSelected("GPIO Input")) // if the pis an input, read and display the input
734 {
735 if (m_pinIO.readBack()) { cs_currentState = "GPIO Input = 1"; }
736 else
737 {
738 cs_currentState = "GPIO Input = 0";
739 }
740 }
741 else if (cc_pinFunction.IsSelected("GPIO Output 0")) // if the pin is an output, display the configured output
742 {
743 cs_currentState = "GPIO Output = 0";
744 }
745 else if (cc_pinFunction.IsSelected("GPIO Output 1"))
746 {
747 cs_currentState = "GPIO Output = 1";
748 }
749 else if (cc_pinFunction.IsSelected("Pin State"))
750 {
751 cs_currentState = "Not Configured";
752 }
753 else
754 {
755 cs_currentState = "Not Configured";
756 }
757 }
758
759 fdprintf(sock, "\r\n\t\t<td><font size=\"2\">");
760 WriteHtmlVariable(sock, ConfigRenderFunc(1, cs_currentState));
761 fdprintf(sock, "\r\n\t\t</font></td>\r\n");
762 }
763
764 void DisplayFunction(int sock)
765 {
766 static char rowLine[sizeof("\r\n\t\t<td><font size=\"2\">")];
767 writestring(sock, rowLine);
768 WriteHtmlVariable(sock, ConfigRenderFunc(2, cc_pinFunction));
769 writestring(sock, "</td>");
770 }
771
772 // void DisplayCurrentState(int sock)
773 // {
774 // if( !valid() )
775 // {
776 // // The pin has not been initialized
777 // cs_currentState = "Not Configured";
778 // }
779 // else
780 // {
781 // if( m_pinIO.readBack() ) { cs_currentState = "1"; }
782 // else { cs_currentState = "0"; }
783 // }
784
785 // static char rowLine[ sizeof( "\r\n\t\t<td><font size=\"2\">") ];
786 // writestring( sock, rowLine );
787 // WriteHtmlVariable(sock,ConfigRenderFunc(1, cs_currentState));
788 // writestring( sock, "</td>" );
789 // }
790
791 uint8_t GetPinFunctionIndex()
792 {
793 NBString pinFuncs(cc_pinFunction.GetChoices());
794
795 // find the position of the cc_pinFunction value within the choices to find the index
796 size_t position = pinFuncs.find(((NBString)cc_pinFunction).c_str());
797
798 uint8_t commaCount = 0;
799 for (size_t start = position; start > 0; start--)
800 {
801 if (pinFuncs[start] == ',') { commaCount++; }
802 }
803
804 return commaCount;
805 }
806
807 // returns < 0 if failed or the NV_PinIOConfig::pin_fn_t configuration that the pin was initialized to.
808 uint8_t InitPinFunction()
809 {
810 if (!valid() || m_pinIO.mask == 0) { return -1; }
811 // Don't initialize pins that are marked as Read Only
812 if (GetFlags() & fConfigReadOnly) { return -2; }
813
814 uint8_t cc_pinFunctionVal = GetPinFunctionIndex();
815
816 switch (cc_pinFunctionVal)
817 {
818 case NV_PinIOConfig::PIN_FN_NO_CONFIG: m_pinIO.function(PinIO::PIN_FN_IN); return NV_PinIOConfig::PIN_FN_IN;
819
820 case NV_PinIOConfig::PIN_FN_IN: m_pinIO.function(PinIO::PIN_FN_IN); return NV_PinIOConfig::PIN_FN_IN;
821
822 case NV_PinIOConfig::NV_PinIOConfig::PIN_FN_OUT_0:
823 m_pinIO.function(PinIO::PIN_FN_OUT);
824 m_pinIO.clr();
825 return NV_PinIOConfig::NV_PinIOConfig::PIN_FN_OUT_0;
826
827 case NV_PinIOConfig::PIN_FN_OUT_1:
828 m_pinIO.function(PinIO::PIN_FN_OUT);
829 m_pinIO.set();
830 return NV_PinIOConfig::PIN_FN_OUT_1;
831
832 case NV_PinIOConfig::PIN_FN_A: m_pinIO.function(PinIO::PIN_FN_A); return NV_PinIOConfig::PIN_FN_A;
833
834 case NV_PinIOConfig::PIN_FN_B: m_pinIO.function(PinIO::PIN_FN_B); return NV_PinIOConfig::PIN_FN_B;
835
836 case NV_PinIOConfig::PIN_FN_C: m_pinIO.function(PinIO::PIN_FN_C); return NV_PinIOConfig::PIN_FN_C;
837
838 case NV_PinIOConfig::PIN_FN_D: m_pinIO.function(PinIO::PIN_FN_D); return NV_PinIOConfig::PIN_FN_D;
839
840 default: return -3;
841 }
842 }
843};
844
845#ifdef SBE70LC
846#define PIN_HEADER_SIZE 20 // J1 Header
847#else
848#define PIN_HEADER_SIZE 50
849#endif
850
851extern NV_PinIOConfig pinHeaderArray[];
852bool InitPinArrayFunctions();
853bool SetGpioConfigToReadOnly(bool bSetToReadOnly);
854bool SetGpioHighCurrentDrive(bool bEnableHighDrive);
855#endif // end SUPPORTED_GPIO_SERVER_PLATFORM
856
857/*
858 ******************************************************************************
859 *
860 * Global Data Declarations
861 *
862 ******************************************************************************
863 */
864/* DHCP object */
865// extern DhcpObject* gDHCPObjPtr;
866
867/* Settings changed flag */
868extern volatile bool Settings_Changed;
869extern volatile int old_config_ver;
870
871/* User parameters */
872extern NV_SettingsStruct NV_Settings;
873
874/* User parameters change flag */
875extern volatile bool gChangedUserParameters;
876
877/* Debugging flag */
878extern bool bShowDebug;
879
880/*
881 * Selection lists for the web page configuration
882 */
883extern const char *IPModeList[];
884extern const char *IPValueList[];
885extern const char *IPOnClickList[];
886extern const char *BaudList[];
887extern const char *BitList[];
888extern const char *ParityList[];
889extern const char *StopList[];
890extern const char *FlowModeList[];
891extern const char *SerialModeListFull[];
892extern const char *SerialModeListRS232[];
893extern const char *SerialModeListRS485[];
894extern const char *SerialModeListHybrid[];
895extern const char *SerialModeListQuad485[];
896extern const char *SerialModeListQuadMMS[];
897extern const char *ConnectMode[];
898extern const char *ProtocolList[];
899/*
900 ******************************************************************************
901 *
902 * Routines
903 *
904 ******************************************************************************
905 */
906/* Save data to file */
907extern bool UserSaveData(char *dataPtr, int dataSize, const char *fileName);
908
909/* Get saved data */
910extern bool UserGetData(char *dataPtr, char *fileName, int dataSize);
911
912extern void RegisterPost(void);
913
914extern void CheckNVSettings(bool returnToFactory = FALSE);
915
916extern void SetAndSaveDefaults(void);
917
918/* For processing hexadecimal break key value */
919extern uint8_t GetHexByte(const char *cp);
920
921#endif /* _SERIALBURNERDATA_H_ */
Lightweight alternative to C++ CString class.
Definition nbstring.h:118
GPIO Pin Class.
Definition coldfire/cpu/MCF5441X/include/cpu_pins.h:14
int8_t getFn()
Get the pin function for the managed pin(s).
Definition cortex-m7/cpu/SAME70/include/cpu_pins.h:97
bool readBack() const
Read the state of the pin(s) line state without changing the pin function or direction.
Definition cortex-m7/cpu/SAME70/include/cpu_pins.h:164
@ PIN_FN_D
Peripheral D.
Definition cortex-m7/cpu/SAME70/include/cpu_pins.h:46
@ PIN_FN_A
Peripheral A.
Definition cortex-m7/cpu/SAME70/include/cpu_pins.h:43
@ PIN_FN_OUT
Output.
Definition coldfire/cpu/MCF5441X/include/cpu_pins.h:51
@ PIN_FN_C
Peripheral C.
Definition cortex-m7/cpu/SAME70/include/cpu_pins.h:45
@ PIN_FN_IN
Input.
Definition coldfire/cpu/MCF5441X/include/cpu_pins.h:50
@ PIN_FN_B
Peripheral B.
Definition cortex-m7/cpu/SAME70/include/cpu_pins.h:44
Configuration Variable for IPADDR4 (IPv4) object types.
Definition config_obj.h:1404
Boolean Configuration Variable.
Definition config_obj.h:932
Chooser Configuration Variable - Select From a List of Items.
Definition config_obj.h:1915
const config_string & SetChoices(const char *in_choices)
Set the list of choices.
Definition config_obj.h:2084
Base class used to create configuration objects.
Definition config_obj.h:277
Password string Configuration Variable.
Definition config_obj.h:1264
String Configuration Variable.
Definition config_obj.h:1055
Unsigned 32-bit Integer Configuration Variable.
Definition config_obj.h:504
Configuration object header file.
NetBurner functions to printf to a file descriptor.
const uint32_t fConfigReadOnly
Variable is read-only.
Definition config_obj.h:72
int fdprintf(int fc, const char *format,...)
printf to a file descriptor
uint32_t mask
Definition cortex-m7/cpu/SAME70/include/cpu_pins.h:35
int writestring(int fd, const char *str)
Write a null terminated ascii string to the stream associated with a file descriptor (fd)....
CONFIG_RENDER_OBJ ConfigRenderFunc(int mode, const char *pobj, int len=20, const char *extra=0)
Render a configuration object as HTML for the specified configuration object.
NetBurner HTTP Web Server File Handling.
NetBurner Network Interface Header File.
Configuration Settings.
Definition Parallax/src/nvsettings.h:13