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 int oldparity
= cfg
->serparity
;/* preserve past reentrant calls */
38 dlg_update_start(ctrl
, dlg
);
39 dlg_listbox_clear(ctrl
, dlg
);
40 for (i
= 0; i
< lenof(parities
); i
++) {
42 dlg_listbox_addwithid(ctrl
, dlg
, parities
[i
].name
,
45 for (i
= j
= 0; i
< lenof(parities
); i
++) {
46 if (mask
& (1 << i
)) {
47 if (oldparity
== parities
[i
].val
) {
48 dlg_listbox_select(ctrl
, dlg
, j
);
54 if (i
== lenof(parities
)) { /* an unsupported setting was chosen */
55 dlg_listbox_select(ctrl
, dlg
, 0);
56 oldparity
= SER_PAR_NONE
;
58 dlg_update_done(ctrl
, dlg
);
59 cfg
->serparity
= oldparity
; /* restore */
60 } else if (event
== EVENT_SELCHANGE
) {
61 int i
= dlg_listbox_index(ctrl
, dlg
);
65 i
= dlg_listbox_getid(ctrl
, dlg
, i
);
70 static void serial_flow_handler(union control
*ctrl
, void *dlg
,
71 void *data
, int event
)
77 {"None", SER_FLOW_NONE
},
78 {"XON/XOFF", SER_FLOW_XONXOFF
},
79 {"RTS/CTS", SER_FLOW_RTSCTS
},
80 {"DSR/DTR", SER_FLOW_DSRDTR
},
82 int mask
= ctrl
->listbox
.context
.i
;
84 Config
*cfg
= (Config
*)data
;
86 if (event
== EVENT_REFRESH
) {
87 int oldflow
= cfg
->serflow
; /* preserve past reentrant calls */
88 dlg_update_start(ctrl
, dlg
);
89 dlg_listbox_clear(ctrl
, dlg
);
90 for (i
= 0; i
< lenof(flows
); i
++) {
92 dlg_listbox_addwithid(ctrl
, dlg
, flows
[i
].name
, flows
[i
].val
);
94 for (i
= j
= 0; i
< lenof(flows
); i
++) {
95 if (mask
& (1 << i
)) {
96 if (oldflow
== flows
[i
].val
) {
97 dlg_listbox_select(ctrl
, dlg
, j
);
103 if (i
== lenof(flows
)) { /* an unsupported setting was chosen */
104 dlg_listbox_select(ctrl
, dlg
, 0);
105 oldflow
= SER_FLOW_NONE
;
107 dlg_update_done(ctrl
, dlg
);
108 cfg
->serflow
= oldflow
; /* restore */
109 } else if (event
== EVENT_SELCHANGE
) {
110 int i
= dlg_listbox_index(ctrl
, dlg
);
114 i
= dlg_listbox_getid(ctrl
, dlg
, i
);
119 void ser_setup_config_box(struct controlbox
*b
, int midsession
,
120 int parity_mask
, int flow_mask
)
122 struct controlset
*s
;
127 extern void config_protocolbuttons_handler(union control
*, void *,
131 * Add the serial back end to the protocols list at the
132 * top of the config box.
134 s
= ctrl_getset(b
, "Session", "hostport",
135 "Specify the destination you want to connect to");
137 for (i
= 0; i
< s
->ncontrols
; i
++) {
139 if (c
->generic
.type
== CTRL_RADIO
&&
140 c
->generic
.handler
== config_protocolbuttons_handler
) {
144 sresize(c
->radio
.buttons
, c
->radio
.nbuttons
, char *);
145 c
->radio
.buttons
[c
->radio
.nbuttons
-1] =
147 c
->radio
.buttondata
=
148 sresize(c
->radio
.buttondata
, c
->radio
.nbuttons
, intorptr
);
149 c
->radio
.buttondata
[c
->radio
.nbuttons
-1] = I(PROT_SERIAL
);
150 if (c
->radio
.shortcuts
) {
152 sresize(c
->radio
.shortcuts
, c
->radio
.nbuttons
, char);
153 c
->radio
.shortcuts
[c
->radio
.nbuttons
-1] = 'r';
160 * Entirely new Connection/Serial panel for serial port
163 ctrl_settitle(b
, "Connection/Serial",
164 "Options controlling local serial lines");
168 * We don't permit switching to a different serial port in
169 * midflight, although we do allow all other
172 s
= ctrl_getset(b
, "Connection/Serial", "serline",
173 "Select a serial line");
174 ctrl_editbox(s
, "Serial line to connect to", 'l', 40,
175 HELPCTX(serial_line
),
176 dlg_stdeditbox_handler
, I(offsetof(Config
,serline
)),
177 I(sizeof(((Config
*)0)->serline
)));
180 s
= ctrl_getset(b
, "Connection/Serial", "sercfg", "Configure the serial line");
181 ctrl_editbox(s
, "Speed (baud)", 's', 40,
182 HELPCTX(serial_speed
),
183 dlg_stdeditbox_handler
, I(offsetof(Config
,serspeed
)), I(-1));
184 ctrl_editbox(s
, "Data bits", 'b', 40,
185 HELPCTX(serial_databits
),
186 dlg_stdeditbox_handler
,I(offsetof(Config
,serdatabits
)),I(-1));
188 * Stop bits come in units of one half.
190 ctrl_editbox(s
, "Stop bits", 't', 40,
191 HELPCTX(serial_stopbits
),
192 dlg_stdeditbox_handler
,I(offsetof(Config
,serstopbits
)),I(-2));
193 ctrl_droplist(s
, "Parity", 'p', 40,
194 HELPCTX(serial_parity
),
195 serial_parity_handler
, I(parity_mask
));
196 ctrl_droplist(s
, "Flow control", 'f', 40,
197 HELPCTX(serial_flow
),
198 serial_flow_handler
, I(flow_mask
));