2 * sercfg.c - the serial-port specific parts of the PuTTY
3 * configuration box. Centralised as cross-platform code because
4 * more than one platform will want to use it, but not part of the
5 * main configuration. The expectation is that each platform's
6 * local config function will call out to ser_setup_config_box() if
7 * it needs to set up the standard serial stuff. (Of course, it can
8 * then apply local tweaks after ser_setup_config_box() returns, if
19 static void serial_parity_handler(union control
*ctrl
, void *dlg
,
20 void *data
, int event
)
26 {"None", SER_PAR_NONE
},
28 {"Even", SER_PAR_EVEN
},
29 {"Mark", SER_PAR_MARK
},
30 {"Space", SER_PAR_SPACE
},
32 int mask
= ctrl
->listbox
.context
.i
;
34 Config
*cfg
= (Config
*)data
;
36 if (event
== EVENT_REFRESH
) {
37 dlg_update_start(ctrl
, dlg
);
38 dlg_listbox_clear(ctrl
, dlg
);
39 for (i
= 0; i
< lenof(parities
); i
++) {
41 dlg_listbox_addwithid(ctrl
, dlg
, parities
[i
].name
,
44 for (i
= j
= 0; i
< lenof(parities
); i
++) {
45 if (cfg
->serparity
== parities
[i
].val
)
46 dlg_listbox_select(ctrl
, dlg
, j
);
50 dlg_update_done(ctrl
, dlg
);
51 } else if (event
== EVENT_SELCHANGE
) {
52 int i
= dlg_listbox_index(ctrl
, dlg
);
56 i
= dlg_listbox_getid(ctrl
, dlg
, i
);
61 static void serial_flow_handler(union control
*ctrl
, void *dlg
,
62 void *data
, int event
)
68 {"None", SER_FLOW_NONE
},
69 {"XON/XOFF", SER_FLOW_XONXOFF
},
70 {"RTS/CTS", SER_FLOW_RTSCTS
},
71 {"DSR/DTR", SER_FLOW_DSRDTR
},
73 int mask
= ctrl
->listbox
.context
.i
;
75 Config
*cfg
= (Config
*)data
;
77 if (event
== EVENT_REFRESH
) {
78 dlg_update_start(ctrl
, dlg
);
79 dlg_listbox_clear(ctrl
, dlg
);
80 for (i
= 0; i
< lenof(flows
); i
++) {
82 dlg_listbox_addwithid(ctrl
, dlg
, flows
[i
].name
, flows
[i
].val
);
84 for (i
= j
= 0; i
< lenof(flows
); i
++) {
85 if (cfg
->serflow
== flows
[i
].val
)
86 dlg_listbox_select(ctrl
, dlg
, j
);
90 dlg_update_done(ctrl
, dlg
);
91 } else if (event
== EVENT_SELCHANGE
) {
92 int i
= dlg_listbox_index(ctrl
, dlg
);
96 i
= dlg_listbox_getid(ctrl
, dlg
, i
);
101 void ser_setup_config_box(struct controlbox
*b
, int midsession
,
102 int parity_mask
, int flow_mask
)
104 struct controlset
*s
;
108 * Add the serial back end to the protocols list at the top of
111 s
= ctrl_getset(b
, "Session", "hostport",
112 "Specify your connection by host name or IP address");
115 extern void config_protocolbuttons_handler(union control
*, void *,
117 for (i
= 0; i
< s
->ncontrols
; i
++) {
119 if (c
->generic
.type
== CTRL_RADIO
&&
120 c
->generic
.handler
== config_protocolbuttons_handler
) {
124 sresize(c
->radio
.buttons
, c
->radio
.nbuttons
, char *);
125 c
->radio
.buttons
[c
->radio
.nbuttons
-1] =
127 c
->radio
.buttondata
=
128 sresize(c
->radio
.buttondata
, c
->radio
.nbuttons
, intorptr
);
129 c
->radio
.buttondata
[c
->radio
.nbuttons
-1] = I(PROT_SERIAL
);
130 if (c
->radio
.shortcuts
) {
132 sresize(c
->radio
.shortcuts
, c
->radio
.nbuttons
, char);
133 c
->radio
.shortcuts
[c
->radio
.nbuttons
-1] = NO_SHORTCUT
;
140 * Entirely new Connection/Serial panel for serial port
143 ctrl_settitle(b
, "Connection/Serial",
144 "Options controlling local serial lines");
148 * We don't permit switching to a different serial port in
149 * midflight, although we do allow all other
152 s
= ctrl_getset(b
, "Connection/Serial", "serline",
153 "Select a serial line");
154 ctrl_editbox(s
, "Serial line to connect to", 'l', 40,
155 HELPCTX(serial_line
),
156 dlg_stdeditbox_handler
, I(offsetof(Config
,serline
)),
157 I(sizeof(((Config
*)0)->serline
)));
160 s
= ctrl_getset(b
, "Connection/Serial", "sercfg", "Configure the serial line");
161 ctrl_editbox(s
, "Speed (baud)", 's', 40,
162 HELPCTX(serial_speed
),
163 dlg_stdeditbox_handler
, I(offsetof(Config
,serspeed
)), I(-1));
164 ctrl_editbox(s
, "Data bits", 'b', 40,
165 HELPCTX(serial_databits
),
166 dlg_stdeditbox_handler
,I(offsetof(Config
,serdatabits
)),I(-1));
168 * Stop bits come in units of one half.
170 ctrl_editbox(s
, "Stop bits", 't', 40,
171 HELPCTX(serial_stopbits
),
172 dlg_stdeditbox_handler
,I(offsetof(Config
,serstopbits
)),I(-2));
173 ctrl_droplist(s
, "Parity", 'p', 40,
174 HELPCTX(serial_parity
),
175 serial_parity_handler
, I(parity_mask
));
176 ctrl_droplist(s
, "Flow control", 'f', 40,
177 HELPCTX(serial_flow
),
178 serial_flow_handler
, I(flow_mask
));