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 Conf *conf = (Conf *)data;
36 if (event == EVENT_REFRESH) {
37 /* Fetching this once at the start of the function ensures we
38 * remember what the right value is supposed to be when
39 * operations below cause reentrant calls to this function. */
40 int oldparity = conf_get_int(conf, CONF_serparity);
42 dlg_update_start(ctrl, dlg);
43 dlg_listbox_clear(ctrl, dlg);
44 for (i = 0; i < lenof(parities); i++) {
46 dlg_listbox_addwithid(ctrl, dlg, parities[i].name,
49 for (i = j = 0; i < lenof(parities); i++) {
50 if (mask & (1 << i)) {
51 if (oldparity == parities[i].val) {
52 dlg_listbox_select(ctrl, dlg, j);
58 if (i == lenof(parities)) { /* an unsupported setting was chosen */
59 dlg_listbox_select(ctrl, dlg, 0);
60 oldparity = SER_PAR_NONE;
62 dlg_update_done(ctrl, dlg);
63 conf_set_int(conf, CONF_serparity, oldparity); /* restore */
64 } else if (event == EVENT_SELCHANGE) {
65 int i = dlg_listbox_index(ctrl, dlg);
69 i = dlg_listbox_getid(ctrl, dlg, i);
70 conf_set_int(conf, CONF_serparity, i);
74 static void serial_flow_handler(union control *ctrl, void *dlg,
75 void *data, int event)
81 {"None", SER_FLOW_NONE},
82 {"XON/XOFF", SER_FLOW_XONXOFF},
83 {"RTS/CTS", SER_FLOW_RTSCTS},
84 {"DSR/DTR", SER_FLOW_DSRDTR},
86 int mask = ctrl->listbox.context.i;
88 Conf *conf = (Conf *)data;
90 if (event == EVENT_REFRESH) {
91 /* Fetching this once at the start of the function ensures we
92 * remember what the right value is supposed to be when
93 * operations below cause reentrant calls to this function. */
94 int oldflow = conf_get_int(conf, CONF_serflow);
96 dlg_update_start(ctrl, dlg);
97 dlg_listbox_clear(ctrl, dlg);
98 for (i = 0; i < lenof(flows); i++) {
100 dlg_listbox_addwithid(ctrl, dlg, flows[i].name, flows[i].val);
102 for (i = j = 0; i < lenof(flows); i++) {
103 if (mask & (1 << i)) {
104 if (oldflow == flows[i].val) {
105 dlg_listbox_select(ctrl, dlg, j);
111 if (i == lenof(flows)) { /* an unsupported setting was chosen */
112 dlg_listbox_select(ctrl, dlg, 0);
113 oldflow = SER_FLOW_NONE;
115 dlg_update_done(ctrl, dlg);
116 conf_set_int(conf, CONF_serflow, oldflow);/* restore */
117 } else if (event == EVENT_SELCHANGE) {
118 int i = dlg_listbox_index(ctrl, dlg);
122 i = dlg_listbox_getid(ctrl, dlg, i);
123 conf_set_int(conf, CONF_serflow, i);
127 void ser_setup_config_box(struct controlbox *b, int midsession,
128 int parity_mask, int flow_mask)
130 struct controlset *s;
135 extern void config_protocolbuttons_handler(union control *, void *,
139 * Add the serial back end to the protocols list at the
140 * top of the config box.
142 s = ctrl_getset(b, "Session", "hostport",
143 "Specify the destination you want to connect to");
145 for (i = 0; i < s->ncontrols; i++) {
147 if (c->generic.type == CTRL_RADIO &&
148 c->generic.handler == config_protocolbuttons_handler) {
152 sresize(c->radio.buttons, c->radio.nbuttons, char *);
153 c->radio.buttons[c->radio.nbuttons-1] =
155 c->radio.buttondata =
156 sresize(c->radio.buttondata, c->radio.nbuttons, intorptr);
157 c->radio.buttondata[c->radio.nbuttons-1] = I(PROT_SERIAL);
158 if (c->radio.shortcuts) {
160 sresize(c->radio.shortcuts, c->radio.nbuttons, char);
161 c->radio.shortcuts[c->radio.nbuttons-1] = 'r';
168 * Entirely new Connection/Serial panel for serial port
171 ctrl_settitle(b, "Connection/Serial",
172 "Options controlling local serial lines");
176 * We don't permit switching to a different serial port in
177 * midflight, although we do allow all other
180 s = ctrl_getset(b, "Connection/Serial", "serline",
181 "Select a serial line");
182 ctrl_editbox(s, "Serial line to connect to", 'l', 40,
183 HELPCTX(serial_line),
184 conf_editbox_handler, I(CONF_serline), I(1));
187 s = ctrl_getset(b, "Connection/Serial", "sercfg", "Configure the serial line");
188 ctrl_editbox(s, "Speed (baud)", 's', 40,
189 HELPCTX(serial_speed),
190 conf_editbox_handler, I(CONF_serspeed), I(-1));
191 ctrl_editbox(s, "Data bits", 'b', 40,
192 HELPCTX(serial_databits),
193 conf_editbox_handler, I(CONF_serdatabits), I(-1));
195 * Stop bits come in units of one half.
197 ctrl_editbox(s, "Stop bits", 't', 40,
198 HELPCTX(serial_stopbits),
199 conf_editbox_handler, I(CONF_serstopbits), I(-2));
200 ctrl_droplist(s, "Parity", 'p', 40,
201 HELPCTX(serial_parity),
202 serial_parity_handler, I(parity_mask));
203 ctrl_droplist(s, "Flow control", 'f', 40,
204 HELPCTX(serial_flow),
205 serial_flow_handler, I(flow_mask));