NetBurner 3.1
SSH/SecureSerToEthFactoryApp/serialburnerdata.h
1 /* Revision: 2.8.7 */
2 
3 /******************************************************************************
4 * Copyright 1998-2018 NetBurner, Inc. ALL RIGHTS RESERVED
5 *
6 * Permission is hereby granted to purchasers of NetBurner Hardware to use or
7 * modify this computer program for any use as long as the resultant program
8 * is only executed on NetBurner provided hardware.
9 *
10 * No other rights to use this program or its derivatives in part or in
11 * whole are granted.
12 *
13 * It may be possible to license this or other NetBurner software for use on
14 * non-NetBurner Hardware. Contact sales@Netburner.com for more information.
15 *
16 * NetBurner makes no representation or warranties with respect to the
17 * performance of this computer program, and specifically disclaims any
18 * responsibility for any damages, special or consequential, connected with
19 * the use of this program.
20 *
21 * NetBurner
22 * 5405 Morehouse Dr.
23 * San Diego, CA 92121
24 * www.netburner.com
25 ******************************************************************************/
26 
27 
28 #ifndef _SERIALBURNERDATA_H_
29 #define _SERIALBURNERDATA_H_
30 
31 /*
32  ******************************************************************************
33  *
34  * Include Files
35  *
36  ******************************************************************************
37  */
38 #include <snmp.h>
39 #include <netbios.h>
40 #include "nbfactory.h"
41 
42 /*
43  ******************************************************************************
44  *
45  * Definitions
46  *
47  ******************************************************************************
48  */
49 /* Constants that go with Protocol and selection list ProtocolList */
50 #define PROTOCOL_UDP_TO_SERIAL ( 1 )
51 #define PROTOCOL_TCP_TO_SERIAL ( 2 )
52 #define PROTOCOL_SSH ( 3 )
53 
54 /* Constants that go with SerialMode and selection list SerialModeList */
55 #define SERIAL_MODE_RS232 ( 1 )
56 #define SERIAL_MODE_DEBUG ( 2 )
57 #define SERIAL_MODE_485H ( 3 )
58 #define SERIAL_MODE_485F ( 4 )
59 #define SERIAL_MODE_485H_ECHO ( 5 ) // Used by PK70 quad UART blade board - S/W configurable
60 #define SERIAL_MODE_485H_NOECHO ( 6 ) // Used by PK70 quad UART blade board - S/W configurable
61 
62 /* Constants that go with serial FlowMode and selection list FlowModeList */
63 #define SERIAL_FLOW_MODE_NONE ( 1 )
64 #define SERIAL_FLOW_MODE_XON_OFF ( 2 )
65 #define SERIAL_FLOW_MODE_RTS_CTS ( 3 )
66 
67 /* Constants that go with serial ConnectMode */
68 #define SERIAL_CONNECT_CONNECT_NEVER ( 1 )
69 #define SERIAL_CONNECT_CONNECT_AT_POWERUP ( 2 )
70 #define SERIAL_CONNECT_CONNECT_WHEN_DATARX ( 3 )
71 #ifdef SB700EX
72 #define SERIAL_CONNECT_CONNECT_WHEN_DSR ( 4 )
73 #define SERIAL_CONNECT_CONNECT_WHEN_CD ( 5 )
74 #endif /* SB700EX */
75 
76 /* Constants that go with IP_Addr_mode */
77 #define IP_ADDR_MODE_DHCP ( 1 )
78 #define IP_ADDR_MODE_STATIC ( 2 )
79 
80 /* Constants that go with character strings */
81 #define CONNECT_NAME_LENGTH ( 79 )
82 #define CONNECT_MESSAGE_LENGTH ( 79 )
83 #define CONNECT_LOSS_MESSAGE_LENGTH ( 79 )
84 #define DEVICE_NAME_LENGTH ( 15 )
85 #define NTP_NAME_LENGTH ( 35 )
86 #define USERNAME_LENGTH ( 39 )
87 #define PASSWORD_LENGTH ( 39 )
88 
89 /* Constants that define buffer sizes */
90 #define MAX_UDP_RX_BUFFER ( 1500 )
91 #define BUFFER_SIZE ( 20000 )
92 
93 /* Constants that define task priorities */
94 #define SNMP_PRIO ( MAIN_PRIO - 2 )
95 #define AT_COM_PRIO ( MAIN_PRIO - 3 )
96 
97 #ifdef NB_FACTORY_INCLUDE_SSH
98 
99  /* Constants that go with SSH character strings */
100  #define SSH_USERNAME_LENGTH ( 39 )
101  #define SSH_PASSWORD_LENGTH ( 39 )
102 
103 #endif /* #ifdef NB_FACTORY_INCLUDE_SSH */
104 
105 #ifdef NB_FACTORY_INCLUDE_SSL
106 
107  /*
108  ******************************************************************************
109  * Key or certificate size
110  * SSL Certificate size 2200 (empirical)
111  * OpenSSL format is Privacy-enhanced Electronic Mail (PEM) encoded
112  * NULL terminated for conversion
113  *
114  ******************************************************************************
115  */
116  #define SERIAL_BURNER_CERTIFICATE_SIZE_MAX ( ( 2 * 1024 ) - 1 )
117  #define SERIAL_BURNER_CERTIFICATE_SIZE_MAX_PEM ( ( 3 * 1024 ) - 1 )
118 
119 #endif /* #ifdef NB_FACTORY_INCLUDE_SSL */
120 
121 #if defined(NB_FACTORY_INCLUDE_SSH) || defined(NB_FACTORY_INCLUDE_SSL)
122 
123  /* Certificate and key status */
124  #define SERIAL_BURNER_LIBRARY_DEFAULT ( (BYTE)0x00 )
125  #define SERIAL_BURNER_DEFAULT ( (BYTE)0x01 )
126  #define SERIAL_BURNER_USER_INSTALLED ( (BYTE)0x02 )
127 
128  /*
129  ******************************************************************************
130  * Key size
131  * SSH MAX_PRIVKEY_SIZE 1700 (options.h)
132  * SSH key size (PEM) < 4K (empirical)
133  * NULL terminated for conversion
134  *
135  ******************************************************************************
136  */
137  #define SERIAL_BURNER_KEY_SIZE_MAX_PEM ( ( 4 * 1024 ) - 1 )
138 
139 #endif /* #if defined(NB_FACTORY_INCLUDE_SSH) || defined(NB_FACTORY_INCLUDE_SSL) */
140 /*
141  ******************************************************************************
142  * HTML support
143  ******************************************************************************
144  */
145 /* HTML data sizes */
146 #define SERIAL_BURNER_HTML_INPUT_NUMBER_SIZE ( 5 )
147 
148 /* HTML data sizes */
149 #define SERIAL_BURNER_HTML_HEX_NUMBER_LENGTH ( 2 )
150 
151 #ifdef SB70LC
152 /* HTML port column width percentage */
153 #define SERIAL_BURNER_PORT_COLUMN_WIDTH_PERCENT \
154  ( 60 / (NB_FACTORY_SERIAL_PORTS + NB_FACTORY_I2C_PORTS))
155 #else
156 #define SERIAL_BURNER_PORT_COLUMN_WIDTH_PERCENT \
157  ( 60 / (NB_FACTORY_SERIAL_PORTS))
158 #endif
159 
160 
161 /* HTML I2C column width percentage */
162 #define SERIAL_BURNER_HTML_I2C_WIDTH ( 70 )
163 
164 /* HTML input name maximum size */
165 #define SERIAL_BURNER_HTML_INPUT_SIZE ( 39 )
166 
167 /* HTML IP address string size */
168 #define SERIAL_BURNER_HTML_IP_STRING_SIZE ( 20 )
169 
170 /* Password protection string (SSH_PASSWORD_LENGTH length ) */
171 #define SERIAL_BURNER_PASSWORD_STRING \
172  "*******************"
173 
174 /*
175  ******************************************************************************
176  * Booting support
177  ******************************************************************************
178  */
179 #define boot_iprintf(...)\
180 { \
181  if ( gConfigRec.m_q_boot == 0 ) \
182  { \
183  iprintf( "%s : ", NV_Settings.DeviceName ); \
184  iprintf( __VA_ARGS__ ); \
185  iprintf( "\r\n" ); \
186  } \
187 }
188 
189 /*
190  ******************************************************************************
191  * Debug support
192  ******************************************************************************
193  */
194 #define debug_iprintf(...)\
195 { \
196  if ( bShowDebug == TRUE ) \
197  { \
198  iprintf( "%s : ", NV_Settings.DeviceName ); \
199  iprintf( __VA_ARGS__ ); \
200  iprintf( "\r\n" ); \
201  } \
202 }
203 
204 /*
205  ******************************************************************************
206  *
207  * Structures
208  *
209  ******************************************************************************
210  */
211 #ifndef SNMP
212  #include <snmp.h>
213  struct SysInfo
214  {
215  char SysContact[ 256 ];
216  char SysName[ 256 ];
217  char SysLocation[ 256 ];
218  unsigned char ReadCommunity[ 40 ];
219  unsigned char WriteCommunity[ 40 ];
220  IPADDR trap_destination;
221  DWORD trap_enable_flags;
222  DWORD valid;
223  };
224 #endif /* SNMP */
225 
226 /*
227  Port Setting (Protocol)
228 
229  * Listening socket (All) *
230  ListenPort - Listen port
231  InactivityTimeoutInSecs - Inactivity timeout in seconds
232  New_connection_timeout - Connection timeout
233  ConnectMode - Serial connect mode
234 
235  * Connect on power-up and received serial data choices (TCP) *
236  ConnectPort - Port
237  ConnectName - Target name for GetHostByName
238  ConnectAddress - Target IP address
239  ConnectIdleTimeout - Idle timeout in seconds
240  Connection_retry_timeout- Retry interval in seconds
241  keepAliveInterval - Check and maintain the connection in second intervals
242 
243  * Primary connection settings - serial port settings (All) *
244  SerialMode - Type port
245  DataBaudRate - Baud rate
246  Output_Bits - Data bits per byte
247  Output_Parity - Parity
248  Output_Stop - Stop bits
249  FlowMode - Flow control
250 
251  * Primary connection settings - serial data notification settings (TCP, UDP) *
252  ConnectMessage - Serial message upon connection
253  ConnectLossMessage - Serial message upon connection loss
254  BreakOnConnect - Send serial break on connection
255  BreakInterval - Break interval
256  BreakKeyFlag - Send data then a break
257  BreakKeyValue - Data prior to break
258 
259  * UDP *
260  UdpAccumulatedChars - Char. to accumulate before sending packet
261  UdpWait - Accumulation wait in ticks
262  UdpTriggerChar - Flushing character
263  bLearnUdp - Learn IP address from connection
264  bUdpCheckFrameingChar - UDP framing character to check
265 
266  * Custom Framing (TCP, SSH) *
267  bTcpCustomFrame - Enabled?
268  TcpAccumulatedChars - Char. to accumulate before sending packet
269  TcpWait - Accumulation wait in ticks
270  TcpTriggerChar - Serial flushing character
271 
272  * Framing (TCP) *
273  bTcpCheckFramingChar - TCP framing character to check
274 
275 */
276 struct NV_OnePortSetting
277 {
278  WORD ListenPort;
279  DWORD InactivityTimeoutInSecs;
280  DWORD New_connection_timeout;
281  BYTE ConnectMode;
282  WORD ConnectPort;
283  char ConnectName[2][ ( CONNECT_NAME_LENGTH + 1 ) ];
284  IPADDR ConnectAddress[2];
285  DWORD ConnectIdleTimeout;
286  DWORD Connection_retry_timeout;
287  DWORD keepAliveInterval;
288  BYTE SerialMode;
289  DWORD DataBaudRate;
290  DWORD CustomBaudRate;
291  BYTE Output_Bits;
292  BYTE Output_Parity;
293  BYTE Output_Stop;
294  BYTE FlowMode;
295  BYTE bDoAtCommand;
296  char ConnectMessage[ ( CONNECT_MESSAGE_LENGTH + 1 ) ];
297  char ConnectLossMessage[ ( CONNECT_LOSS_MESSAGE_LENGTH + 1 ) ];
298  BYTE BreakOnConnect;
299  WORD BreakInterval;
300  BYTE BreakKeyFlag;
301  BYTE BreakKeyValue;
302  WORD UdpAccumulatedChars;
303  WORD UdpWait;
304  WORD TcpAccumulatedChars;
305  WORD TcpWait;
306  BYTE UdpTriggerChar;
307  BYTE TcpTriggerChar;
308  BOOL bTcpCustomFrame;
309  BOOL bLearnUdp;
310  BOOL bUdpCheckFrameingChar;
311  BOOL bTcpCheckFramingChar;
312  BOOL bAlwaysStoreSerialChars;
313 #ifdef SB700EX
314  BOOL bDTRReflectsConnection;
315 #endif /* SB700EX */
316  BOOL bTCPasSSL;
317 };
318 
319 
320 /* ic - The byte value written to the I2FDR register of the processor
321  * to reach a desired frequency divider. Used with InitI2C() to
322  * initialize the bus to a particular I2C bus speed
323  * FreqDivider - The frequency divider that corresponds to the byte value in ic.
324  * For a table of ic-frequency divider pairs, refer to the reference manual for the
325  * processor - specifically, refer to the I2FDR section of the
326  * I2C chapter.
327  */
328 struct NV_OneI2CPortSetting
329 {
330  // I2C parameters
331  unsigned char ic;
332  unsigned long FreqDivider;
333  unsigned long CustomBaudRate;
334  unsigned char SetMasterAddress;
335  unsigned char SaveMasterAddress;
336 
337  // TCP parameters
338  unsigned short ListenPort;
339  unsigned long InactivityTimeoutInSecs;
340  unsigned long New_connection_timeout;
341  unsigned long ConnectIdleTimeout;
342  bool bTCPasSSL;
343 };
344 
345 /* Refer to the I2FDR section of the reference manual for the processor in use
346  * for a table of dividers and the respective ICs's */
347 struct BaudRate
348 {
349  unsigned char ic;
350  int divider;
351 };
352 
353 
354 /*
355  Configuration Settings
356 
357  * Configuration *
358  Protocol - Network to serial protocol
359  DeviceName - Device name for DHCP
360  NetBIOSName - NetBIOS name
361  IP_Addr_mode - Static or dynamic address mode
362  ports - Network and serial ports
363  SysInfoData - SMNP
364  UserName - User name for changes, SSH login
365  Password - Password for changes, SSH login
366 
367  * SSH *
368  SshUserName - User name for SSH login
369  SshPassword - Password for SSH login
370 
371  * SSL and SSH *
372  CertificateRsaLength - Certificate length
373  CertificateData - Certificate
374  KeyHttpsRsaLength - RSA key for HTTPS length, 0 is none
375  KeyHttpsRsaData - RSA key for HTTPS
376  KeyRsaLength - RSA key length, 0 is none
377  KeyRsaData - RSA key
378  KeyDsaLength - DSA key length, 0 is none
379  KeyDsaData - DSA key
380 
381  * Version change key *
382  VerifyKey - Version change key
383 
384 */
385 struct NV_SettingsStruct
386 {
387  /* NetBurner protocol */
388  BYTE Protocol;
389 
390  /* NetBurner address configuration */
391  char DeviceName[ ( DEVICE_NAME_LENGTH + 1 ) ];
392  char NetBIOSName[ ( NETBIOS_NAME_SIZE_IN_CHARS + 1 ) ];
393  char NTPName[ NTP_NAME_LENGTH+ 1 ];
394  IPADDR4 NTP_Addr;
395 
396  BYTE IP_Addr_mode;
397  NV_OnePortSetting ports[ NB_FACTORY_SERIAL_PORTS ];
398 
399  SysInfo SysInfoData;
400  char UserName[ ( USERNAME_LENGTH + 1 ) ];
401  char Password[ ( PASSWORD_LENGTH + 1 ) ];
402 
403  /* I2C address */
404  //char I2CAddress[3];
405  char slaveI2CAddress[3];
406 
407  //#if (defined SB70LC ) // || MCF5441X || NANO54415)
408  NV_OneI2CPortSetting i2c_port;
409  //#endif
410 
411 #ifdef NB_FACTORY_INCLUDE_SSL
412 
413  /* SSL certificate and keys file lengths */
414  BYTE SslCertificateSource;
415  WORD SslCertificateLength;
416  WORD SslKeyLength;
417 
418 #endif /* #ifdef NB_FACTORY_INCLUDE_SSL */
419 
420 #ifdef NB_FACTORY_INCLUDE_SSH
421 
422  /* SSH user name and password */
423  char SshUserName[ ( SSH_USERNAME_LENGTH + 1 ) ];
424  char SshPassword[ ( SSH_PASSWORD_LENGTH + 1 ) ];
425 
426  /* SSH key source and lengths (default and user installed) */
427  BYTE SshKeyRsaSource;
428  WORD SshKeyRsaLength;
429  BYTE SshKeyDsaSource;
430  WORD SshKeyDsaLength;
431 
432 #endif /* #ifdef NB_FACTORY_INCLUDE_SSH */
433 
434  BOOL bAllowAtToAccessAPassword;
435  BOOL bAllowAtToAccessSPassword;
436 
437  /* Version verification key */
438  DWORD VerifyKey;
439 
440  /* Flash File System Version verification key */
441  DWORD STDEFFSVerifyKey;
442 
443 #ifdef SB800EX
444  BYTE Wifi_IP_Addr_mode;
445 #endif
446 };
447 
448 /*
449  ******************************************************************************
450  *
451  * Global Data Declarations
452  *
453  ******************************************************************************
454  */
455 /* DHCP object */
456 //extern DhcpObject* gDHCPObjPtr;
457 
458 /* Settings changed flag */
459 extern volatile BOOL Settings_Changed;
460 
461 /* User parameters */
462 extern NV_SettingsStruct NV_Settings;
463 
464 /* User parameters change candidate */
465 extern NV_SettingsStruct gNV_SettingsChangeCopy;
466 
467 /* User parameters change flag */
468 extern volatile BOOL gChangedUserParameters;
469 
470 /* Configuration record change candidate */
471 extern ConfigRecord gConfigRecordChangeCopy;
472 
473 /* User parameters change flag */
474 extern volatile BOOL gChangedConfigurationRecord;
475 
476 /* Debugging flag */
477 extern BOOL bShowDebug;
478 
479 /*
480  * Selection lists for the web page configuration
481  */
482 extern const char* IPModeList[];
483 extern const char* IPValueList[];
484 extern const char* IPOnClickList[];
485 extern const char* BaudList[];
486 extern const char* BitList[];
487 extern const char* ParityList[];
488 extern const char* StopList[];
489 extern const char* FlowModeList[];
490 extern const char* SerialModeListFull[];
491 extern const char* SerialModeListRS232[];
492 extern const char* SerialModeListRS485[];
493 extern const char* SerialModeListHybrid[];
494 extern const char* SerialModeListQuad485[];
495 extern const char* SerialModeListQuadMMS[];
496 extern const char* ConnectMode[];
497 extern const char* ProtocolList[];
498 extern BYTE SerialModeCapability[];
499 /*
500  ******************************************************************************
501  *
502  * Routines
503  *
504  ******************************************************************************
505  */
506 /* Save data to file */
507 extern BOOL UserSaveData( char* dataPtr, int dataSize, const char* fileName );
508 
509 /* Get saved data */
510 extern BOOL UserGetData( char* dataPtr, char* fileName, int dataSize );
511 
512 extern void RegisterPost( void );
513 
514 extern void CheckNVSettings( BOOL returnToFactory = FALSE );
515 
516 extern void SetAndSaveDefaults( void );
517 
518 /* For processing hexadecimal break key value */
519 extern char GetHexByte( const char* cp );
520 
521 #endif /* _SERIALBURNERDATA_H_ */
Used to hold and manipulate IPv4 and IPv6 addresses in dual stack mode.
Definition: ipv6_addr.h:28
void CheckNVSettings()
Definition: webif.cpp:40