Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change smartcard speed configuration in BBIO mode to custom value #88

Merged
merged 2 commits into from
Dec 8, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 31 additions & 44 deletions src/hydrabus/hydrabus_bbio_smartcard.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
#include "hydrabus_bbio_smartcard.h"
#include "bsp_smartcard.h"

#define SMARTCARD_DEFAULT_SPEED (9600)

void bbio_smartcard_init_proto_default(t_hydra_console *con)
{
mode_config_proto_t* proto = &con->mode->proto;
Expand Down Expand Up @@ -57,6 +59,8 @@ void bbio_mode_smartcard(t_hydra_console *con)
uint8_t *tx_data = (uint8_t *)g_sbuf;
uint8_t *rx_data = (uint8_t *)g_sbuf+4096;
uint8_t data;
uint32_t dev_speed=0;
uint32_t final_baudrate;
bsp_status_t status;
mode_config_proto_t* proto = &con->mode->proto;

Expand Down Expand Up @@ -148,51 +152,34 @@ void bbio_mode_smartcard(t_hydra_console *con)
i++;
}
break;
default:
if ((bbio_subcommand & BBIO_SMARTCARD_SET_SPEED) == BBIO_SMARTCARD_SET_SPEED) {
switch(bbio_subcommand & 0b1111) {
case 0:
proto->config.smartcard.dev_speed = 640;
break;
case 1:
proto->config.smartcard.dev_speed = 1200;
break;
case 2:
proto->config.smartcard.dev_speed = 2400;
break;
case 3:
proto->config.smartcard.dev_speed = 4800;
break;
case 4:
proto->config.smartcard.dev_speed = 9600;
break;
case 5:
proto->config.smartcard.dev_speed = 19200;
break;
case 6:
proto->config.smartcard.dev_speed = 31250;
break;
case 7:
proto->config.smartcard.dev_speed = 38400;
break;
case 8:
proto->config.smartcard.dev_speed = 57600;
break;
case 10:
proto->config.smartcard.dev_speed = 115200;
break;
default:
cprint(con, "\x00", 1);
continue;
}
case BBIO_SMARTCARD_SET_SPEED:
chnRead(con->sdu, rx_data, 4);
dev_speed = rx_data[0] << 24;
dev_speed += rx_data[1] << 16;
dev_speed += rx_data[2] << 8;
dev_speed += rx_data[3];

status = bsp_smartcard_init(proto->dev_num, proto);
if(status == BSP_OK) {
cprint(con, "\x01", 1);
} else {
cprint(con, "\x00", 1);
}
} else if ((bbio_subcommand & BBIO_SMARTCARD_CONFIG) == BBIO_SMARTCARD_CONFIG) {
proto->config.smartcard.dev_speed = dev_speed;
status = bsp_smartcard_init(proto->dev_num, proto);

if(status != BSP_OK) {
cprint(con, "\x00", 1);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should reset to default speed in case of error.
Add the following lines here

proto->config.smartcard.dev_speed = SMARTCARD_DEFAULT_SPEED;
bsp_smartcard_init(proto->dev_num, proto);

proto->config.smartcard.dev_speed = SMARTCARD_DEFAULT_SPEED;
bsp_smartcard_init(proto->dev_num, proto);
break;
}
final_baudrate = bsp_smartcard_get_final_baudrate(proto->dev_num);
if(final_baudrate < 1) {
cprintf(con, "\x00", 1);
proto->config.smartcard.dev_speed = SMARTCARD_DEFAULT_SPEED;
bsp_smartcard_init(proto->dev_num, proto);
}
else{
cprint(con, "\x01", 1);
}
break;
default:
if ((bbio_subcommand & BBIO_SMARTCARD_CONFIG) == BBIO_SMARTCARD_CONFIG) {
proto->config.smartcard.dev_polarity =
(bbio_subcommand & 0b1)?1:0;
proto->config.smartcard.dev_stop_bit =
Expand Down