Add some validation for invalid router destinations

example_keyboards
Fred Sundvik 9 years ago
parent 532f98eef6
commit ea346125e8

@ -33,7 +33,9 @@ void router_set_master(bool master) {
void route_incoming_frame(uint8_t link, uint8_t* data, uint16_t size){
if (is_master) {
transport_recv_frame(data[size-1], data, size - 1);
if (link == DOWN_LINK) {
transport_recv_frame(data[size-1], data, size - 1);
}
}
else {
if (link == UP_LINK) {
@ -52,11 +54,15 @@ void route_incoming_frame(uint8_t link, uint8_t* data, uint16_t size){
void router_send_frame(uint8_t destination, uint8_t* data, uint16_t size) {
if (destination == 0) {
data[size] = 1;
validator_send_frame(UP_LINK, data, size + 1);
if (!is_master) {
data[size] = 1;
validator_send_frame(UP_LINK, data, size + 1);
}
}
else {
data[size] = destination;
validator_send_frame(DOWN_LINK, data, size + 1);
if (is_master) {
data[size] = destination;
validator_send_frame(DOWN_LINK, data, size + 1);
}
}
}

@ -174,7 +174,6 @@ Ensure(FrameRouter, first_link_sends_to_master) {
}
Ensure(FrameRouter, second_link_sends_to_master) {
printf("Second to master start\n");
frame_buffer_t data;
data.data = 0xAB7055BB;
activate_router(2);
@ -195,3 +194,38 @@ Ensure(FrameRouter, second_link_sends_to_master) {
assert_that(router_buffers[0].send_buffers[DOWN_LINK].sent_data_size, is_equal_to(0));
assert_that(router_buffers[0].send_buffers[UP_LINK].sent_data_size, is_equal_to(0));
}
Ensure(FrameRouter, master_sends_to_master_does_nothing) {
frame_buffer_t data;
data.data = 0xAB7055BB;
activate_router(0);
router_send_frame(0, (uint8_t*)&data, 4);
assert_that(router_buffers[0].send_buffers[UP_LINK].sent_data_size, is_equal_to(0));
assert_that(router_buffers[0].send_buffers[DOWN_LINK].sent_data_size, is_equal_to(0));
}
Ensure(FrameRouter, link_sends_to_other_link_does_nothing) {
frame_buffer_t data;
data.data = 0xAB7055BB;
activate_router(1);
router_send_frame(2, (uint8_t*)&data, 4);
assert_that(router_buffers[1].send_buffers[UP_LINK].sent_data_size, is_equal_to(0));
assert_that(router_buffers[1].send_buffers[DOWN_LINK].sent_data_size, is_equal_to(0));
}
Ensure(FrameRouter, master_receives_on_uplink_does_nothing) {
frame_buffer_t data;
data.data = 0xAB7055BB;
activate_router(1);
router_send_frame(0, (uint8_t*)&data, 4);
assert_that(router_buffers[1].send_buffers[UP_LINK].sent_data_size, is_greater_than(0));
assert_that(router_buffers[1].send_buffers[DOWN_LINK].sent_data_size, is_equal_to(0));
never_expect(transport_recv_frame);
activate_router(0);
receive_data(UP_LINK,
router_buffers[1].send_buffers[UP_LINK].sent_data,
router_buffers[1].send_buffers[UP_LINK].sent_data_size);
assert_that(router_buffers[0].send_buffers[UP_LINK].sent_data_size, is_equal_to(0));
assert_that(router_buffers[0].send_buffers[DOWN_LINK].sent_data_size, is_equal_to(0));
}

Loading…
Cancel
Save