AmendHub

Download:

jcs

/

subtext

/

amendments

/

259

serial: Allow bits/parity/stop to be configured, default to 8N1


jcs made amendment 259 about 1 year ago
--- db.c Wed Sep 21 17:41:22 2022 +++ db.c Sat Oct 1 20:42:40 2022 @@ -36,45 +36,55 @@ struct struct_field config_fields[] = { { "Location", CONFIG_TYPE_STRING, offsetof(struct config, location), 1, member_size(struct config, location) }, + { "Timezone (Abbrev)", CONFIG_TYPE_STRING, + offsetof(struct config, timezone), + 1, member_size(struct config, timezone) }, + { "Allow Open Signup", CONFIG_TYPE_BOOLEAN, + offsetof(struct config, open_signup), + 0, 0 }, + { "Hostname", CONFIG_TYPE_STRING, offsetof(struct config, hostname), 1, member_size(struct config, hostname) }, { "Telnet Port", CONFIG_TYPE_SHORT, offsetof(struct config, telnet_port), 0, 65535 }, + { "Telnet Trusted Proxy IP", CONFIG_TYPE_IP, offsetof(struct config, trusted_proxy_ip), 0, 1 }, { "Telnet Trusted Proxy UDP Port", CONFIG_TYPE_SHORT, offsetof(struct config, trusted_proxy_udp_port), 0, 65535 }, + { "Modem Port", CONFIG_TYPE_SHORT, offsetof(struct config, modem_port), 0, 2 }, { "Modem Port Speed", CONFIG_TYPE_LONG, offsetof(struct config, modem_speed), 300, 115200 }, + { "Modem Bits/Parity/Stop", CONFIG_TYPE_STRING, + offsetof(struct config, modem_parity), + member_size(struct config, modem_parity), + member_size(struct config, modem_parity) }, { "Modem Init String", CONFIG_TYPE_STRING, offsetof(struct config, modem_init), 1, member_size(struct config, modem_init) }, + { "Max Idle Minutes", CONFIG_TYPE_SHORT, offsetof(struct config, max_idle_minutes), 1, USHRT_MAX }, { "Max Login Seconds", CONFIG_TYPE_SHORT, offsetof(struct config, max_login_seconds), 1, USHRT_MAX }, - { "Timezone (Abbrev)", CONFIG_TYPE_STRING, - offsetof(struct config, timezone), - 1, member_size(struct config, timezone) }, - { "Allow Open Signup", CONFIG_TYPE_BOOLEAN, - offsetof(struct config, open_signup), - 0, 0 }, + { "Screen Blanker Idle Seconds", CONFIG_TYPE_SHORT, offsetof(struct config, blanker_idle_seconds), 1, USHRT_MAX }, { "Screen Blanker Runtime Seconds", CONFIG_TYPE_SHORT, offsetof(struct config, blanker_runtime_seconds), 1, USHRT_MAX }, + { "Session Log History Days", CONFIG_TYPE_SHORT, offsetof(struct config, session_log_days), 1, USHRT_MAX }, @@ -264,6 +274,7 @@ db_migrate(struct db *tdb, short is_new) tdb->config.modem_port = 0; tdb->config.modem_speed = 19200; sprintf(tdb->config.modem_init, "ATQ0V1S0=2"); + sprintf(tdb->config.modem_parity, "8N1"); tdb->config.max_idle_minutes = 5; tdb->config.max_login_seconds = 90; tdb->config.blanker_idle_seconds = (60 * 60); @@ -325,6 +336,7 @@ db_migrate(struct db *tdb, short is_new) bile_read(tdb->bile, DB_CONFIG_RTYPE, 1, (char *)&new_config, sizeof(new_config)); + new_config.open_signup = 0; bile_write(tdb->bile, DB_CONFIG_RTYPE, 1, &new_config, @@ -337,6 +349,7 @@ db_migrate(struct db *tdb, short is_new) bile_read(tdb->bile, DB_CONFIG_RTYPE, 1, (char *)&new_config, sizeof(new_config)); + new_config.max_login_seconds = 90; bile_write(tdb->bile, DB_CONFIG_RTYPE, 1, &new_config, @@ -349,6 +362,7 @@ db_migrate(struct db *tdb, short is_new) bile_read(tdb->bile, DB_CONFIG_RTYPE, 1, (char *)&new_config, sizeof(new_config)); + new_config.blanker_idle_seconds = (60 * 60); new_config.blanker_runtime_seconds = 30; @@ -362,6 +376,7 @@ db_migrate(struct db *tdb, short is_new) bile_read(tdb->bile, DB_CONFIG_RTYPE, 1, (char *)&new_config, sizeof(new_config)); + new_config.trusted_proxy_ip = 0; bile_write(tdb->bile, DB_CONFIG_RTYPE, 1, &new_config, @@ -374,6 +389,7 @@ db_migrate(struct db *tdb, short is_new) bile_read(tdb->bile, DB_CONFIG_RTYPE, 1, (char *)&new_config, sizeof(new_config)); + new_config.modem_speed = 19200; bile_write(tdb->bile, DB_CONFIG_RTYPE, 1, &new_config, @@ -386,6 +402,7 @@ db_migrate(struct db *tdb, short is_new) bile_read(tdb->bile, DB_CONFIG_RTYPE, 1, (char *)&new_config, sizeof(new_config)); + new_config.trusted_proxy_udp_port = 0; bile_write(tdb->bile, DB_CONFIG_RTYPE, 1, &new_config, @@ -468,7 +485,21 @@ db_migrate(struct db *tdb, short is_new) bile_read(tdb->bile, DB_CONFIG_RTYPE, 1, (char *)&new_config, sizeof(new_config)); + new_config.session_log_days = 21; + + bile_write(tdb->bile, DB_CONFIG_RTYPE, 1, &new_config, + sizeof(new_config)); + break; + } + case 11: { + /* 11->12, added modem_parity */ + struct config new_config = { 0 }; + + bile_read(tdb->bile, DB_CONFIG_RTYPE, 1, (char *)&new_config, + sizeof(new_config)); + + sprintf(tdb->config.modem_parity, "8N1"); bile_write(tdb->bile, DB_CONFIG_RTYPE, 1, &new_config, sizeof(new_config)); --- db.h Wed Sep 21 17:12:35 2022 +++ db.h Sat Oct 1 20:14:31 2022 @@ -23,7 +23,7 @@ #define DB_TYPE 'STDB' -#define DB_CUR_VERS 11 +#define DB_CUR_VERS 12 #define DB_TRUE 0x100 #define DB_FALSE 0x000 @@ -82,6 +82,7 @@ struct config { unsigned long modem_speed; unsigned short trusted_proxy_udp_port; short session_log_days; + char modem_parity[4]; }; extern struct struct_field config_fields[]; --- serial.c Fri Jan 1 02:06:20 1904 +++ serial.c Sat Oct 1 20:26:42 2022 @@ -99,8 +99,7 @@ serial_init(void) Str32 in_port = "\p.AIn"; Str32 out_port = "\p.AOut"; SerShk flags = { 0 }; - long baud; - short error; + short baud, error, parity; if (db->config.modem_port == 0) return; @@ -152,22 +151,32 @@ serial_init(void) db->config.modem_speed = 19200; baud = baud19200; } - - logger_printf(logger, "[modem] Initializing %s port at %ld", + + if (strcmp(db->config.modem_parity, "7E1") == 0) { + parity = data7 + evenParity + stop10; + } else { + if (strcmp(db->config.modem_parity, "8N1") != 0) { + logger_printf(logger, + "[modem] Unknown parity \"%s\", using 8N1", + db->config.modem_parity); + snprintf(db->config.modem_parity, + sizeof(db->config.modem_parity), "8N1"); + } + parity = data8 + noParity + stop10; + } + + logger_printf(logger, "[modem] Initializing %s port at %ld (%s)", (db->config.modem_port == 2 ? "printer" : "modem"), - db->config.modem_speed); + db->config.modem_speed, db->config.modem_parity); if ((error = OpenDriver(out_port, &serial_out_refnum)) != 0) panic("OpenDriver(%s) failed: %d", PtoCstr(out_port), error); if ((error = OpenDriver(in_port, &serial_in_refnum)) != 0) panic("OpenDriver(%s) failed: %d", PtoCstr(in_port), error); - /* 8N1 */ - if ((error = SerReset(serial_out_refnum, - baud + data8 + noParity + stop10)) != 0) + if ((error = SerReset(serial_out_refnum, baud + parity)) != 0) panic("SerReset(out) failed: %d", error); - if ((error = SerReset(serial_in_refnum, - baud + data8 + noParity + stop10)) != 0) + if ((error = SerReset(serial_in_refnum, baud + parity)) != 0) panic("SerReset(in) failed: %d", error); SerSetBuf(serial_in_refnum, (Ptr)&serial_input_internal_buf,