+ free(config);
+
+ RETURN();
+}
+
+enum sp_return sp_get_config(struct sp_port *port, struct sp_port_config *config)
+{
+ struct port_data data;
+
+ TRACE("%p, %p", port, config);
+
+ CHECK_OPEN_PORT();
+
+ if (!config)
+ RETURN_ERROR(SP_ERR_ARG, "Null config");
+
+ TRY(get_config(port, &data, config));
+
+ RETURN_OK();
+}
+
+enum sp_return sp_set_config(struct sp_port *port, const struct sp_port_config *config)
+{
+ struct port_data data;
+ struct sp_port_config prev_config;
+
+ TRACE("%p, %p", port, config);
+
+ CHECK_OPEN_PORT();
+
+ if (!config)
+ RETURN_ERROR(SP_ERR_ARG, "Null config");
+
+ TRY(get_config(port, &data, &prev_config));
+ TRY(set_config(port, &data, config));
+
+ RETURN_OK();
+}
+
+#define CREATE_ACCESSORS(x, type) \
+enum sp_return sp_set_##x(struct sp_port *port, type x) { \
+ struct port_data data; \
+ struct sp_port_config config; \
+ TRACE("%p, %d", port, x); \
+ CHECK_OPEN_PORT(); \
+ TRY(get_config(port, &data, &config)); \
+ config.x = x; \
+ TRY(set_config(port, &data, &config)); \
+ RETURN_OK(); \
+} \
+enum sp_return sp_get_config_##x(const struct sp_port_config *config, type *x) { \
+ TRACE("%p, %p", config, x); \
+ if (!config) \
+ RETURN_ERROR(SP_ERR_ARG, "Null config"); \
+ *x = config->x; \
+ RETURN_OK(); \
+} \
+enum sp_return sp_set_config_##x(struct sp_port_config *config, type x) { \
+ TRACE("%p, %d", config, x); \
+ if (!config) \
+ RETURN_ERROR(SP_ERR_ARG, "Null config"); \
+ config->x = x; \
+ RETURN_OK(); \
+}
+
+CREATE_ACCESSORS(baudrate, int)
+CREATE_ACCESSORS(bits, int)
+CREATE_ACCESSORS(parity, enum sp_parity)
+CREATE_ACCESSORS(stopbits, int)
+CREATE_ACCESSORS(rts, enum sp_rts)
+CREATE_ACCESSORS(cts, enum sp_cts)
+CREATE_ACCESSORS(dtr, enum sp_dtr)
+CREATE_ACCESSORS(dsr, enum sp_dsr)
+CREATE_ACCESSORS(xon_xoff, enum sp_xonxoff)
+
+enum sp_return sp_set_config_flowcontrol(struct sp_port_config *config, enum sp_flowcontrol flowcontrol)
+{
+ if (!config)
+ RETURN_ERROR(SP_ERR_ARG, "Null configuration");
+
+ if (flowcontrol > SP_FLOWCONTROL_DTRDSR)
+ RETURN_ERROR(SP_ERR_ARG, "Invalid flow control setting");
+
+ if (flowcontrol == SP_FLOWCONTROL_XONXOFF)
+ config->xon_xoff = SP_XONXOFF_INOUT;
+ else
+ config->xon_xoff = SP_XONXOFF_DISABLED;
+
+ if (flowcontrol == SP_FLOWCONTROL_RTSCTS) {
+ config->rts = SP_RTS_FLOW_CONTROL;
+ config->cts = SP_CTS_FLOW_CONTROL;
+ } else {
+ if (config->rts == SP_RTS_FLOW_CONTROL)
+ config->rts = SP_RTS_ON;
+ config->cts = SP_CTS_IGNORE;