1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-15 12:08:59 +00:00

modtrezormsg: add udp ping handling to modtrezormsg-unix.h

This commit is contained in:
Jan Pochyla 2017-06-06 19:02:54 +02:00
parent fa40e32b93
commit 4a359d2d35
2 changed files with 8 additions and 9 deletions

View File

@ -57,6 +57,10 @@ ssize_t msg_recv(uint8_t *iface, uint8_t *buf, size_t len)
}
si_other = si;
slen = sl;
if (r == 8 && memcmp("PINGPING", buf, 8) == 0) {
msg_send(0, (const uint8_t *)"PONGPONG", 8);
return 0;
}
return r;
}

View File

@ -429,15 +429,10 @@ STATIC mp_obj_t mod_TrezorMsg_Msg_select(mp_obj_t self, mp_obj_t timeout_us) {
uint8_t recvbuf[64];
ssize_t l = msg_recv(&iface, recvbuf, 64);
if (l > 0) {
if (l == 8 && memcmp("PINGPING", recvbuf, 8) == 0) {
msg_send(iface, (const uint8_t *)"PONGPONG", 8);
return mp_const_none;
} else {
mp_obj_tuple_t *tuple = MP_OBJ_TO_PTR(mp_obj_new_tuple(2, NULL));
tuple->items[0] = MP_OBJ_NEW_SMALL_INT(iface);
tuple->items[1] = mp_obj_new_str_of_type(&mp_type_bytes, recvbuf, l);
return MP_OBJ_FROM_PTR(tuple);
}
mp_obj_tuple_t *tuple = MP_OBJ_TO_PTR(mp_obj_new_tuple(2, NULL));
tuple->items[0] = MP_OBJ_NEW_SMALL_INT(iface);
tuple->items[1] = mp_obj_new_str_of_type(&mp_type_bytes, recvbuf, l);
return MP_OBJ_FROM_PTR(tuple);
}
if (timeout <= 0) {
break;