From 67c0ecfb2318e97d1837178e0c3c5460e4dafd50 Mon Sep 17 00:00:00 2001 From: Pavol Rusnak Date: Fri, 6 May 2016 01:57:29 +0200 Subject: [PATCH] add possibility to change UDP ip+port via env variables --- .../modtrezorcrypto/modtrezorcrypto-nist256p1.h | 2 +- .../modtrezorcrypto/modtrezorcrypto-secp256k1.h | 2 +- extmod/modtrezormsg/modtrezormsg-unix.h | 17 ++++++++++++++--- extmod/modtrezorui/modtrezorui-stmhal.h | 2 +- send_udp.py | 5 +++-- 5 files changed, 20 insertions(+), 8 deletions(-) diff --git a/extmod/modtrezorcrypto/modtrezorcrypto-nist256p1.h b/extmod/modtrezorcrypto/modtrezorcrypto-nist256p1.h index 1892d020..52259ab7 100644 --- a/extmod/modtrezorcrypto/modtrezorcrypto-nist256p1.h +++ b/extmod/modtrezorcrypto/modtrezorcrypto-nist256p1.h @@ -8,7 +8,7 @@ #include "py/objstr.h" #include "trezor-crypto/ecdsa.h" -#include "trezor.crypto.curve.nist256p1.h" +#include "trezor-crypto/nist256p1.h" typedef struct _mp_obj_Nist256p1_t { mp_obj_base_t base; diff --git a/extmod/modtrezorcrypto/modtrezorcrypto-secp256k1.h b/extmod/modtrezorcrypto/modtrezorcrypto-secp256k1.h index c39898ac..e32c2a1a 100644 --- a/extmod/modtrezorcrypto/modtrezorcrypto-secp256k1.h +++ b/extmod/modtrezorcrypto/modtrezorcrypto-secp256k1.h @@ -8,7 +8,7 @@ #include "py/objstr.h" #include "trezor-crypto/ecdsa.h" -#include "trezor.crypto.curve.secp256k1.h" +#include "trezor-crypto/secp256k1.h" typedef struct _mp_obj_Secp256k1_t { mp_obj_base_t base; diff --git a/extmod/modtrezormsg/modtrezormsg-unix.h b/extmod/modtrezormsg/modtrezormsg-unix.h index 988f6bc0..1cfd5504 100644 --- a/extmod/modtrezormsg/modtrezormsg-unix.h +++ b/extmod/modtrezormsg/modtrezormsg-unix.h @@ -2,8 +2,9 @@ #include #include #include +#include -#define TREZOR_PORT 21324 +#define TREZOR_UDP_PORT 21324 static int s; static struct sockaddr_in si_me, si_other; @@ -17,8 +18,18 @@ void msg_init(void) fcntl(s, F_SETFL, O_NONBLOCK); si_me.sin_family = AF_INET; - si_me.sin_port = htons(TREZOR_PORT); - si_me.sin_addr.s_addr = htonl(INADDR_ANY); + const char *ip = getenv("TREZOR_UDP_IP"); + if (ip) { + si_me.sin_addr.s_addr = inet_addr(ip); + } else { + si_me.sin_addr.s_addr = htonl(INADDR_LOOPBACK); + } + const char *port = getenv("TREZOR_UDP_PORT"); + if (port) { + si_me.sin_port = htons(atoi(port)); + } else { + si_me.sin_port = htons(TREZOR_UDP_PORT); + } int b; b = bind(s, (struct sockaddr*)&si_me, sizeof(si_me)); diff --git a/extmod/modtrezorui/modtrezorui-stmhal.h b/extmod/modtrezorui/modtrezorui-stmhal.h index 4013d2c3..66efdb7e 100644 --- a/extmod/modtrezorui/modtrezorui-stmhal.h +++ b/extmod/modtrezorui/modtrezorui-stmhal.h @@ -10,7 +10,7 @@ #define CMD(X) (*((__IO uint8_t *)((uint32_t)(0x60000000))) = (X)) #define DATA(X) (*((__IO uint8_t *)((uint32_t)(0x60000000 | 0x10000))) = (X)) -static void DATAS(void *bytes, int len); +static void DATAS(const void *bytes, int len); void sram_init(void) { __GPIOE_CLK_ENABLE(); diff --git a/send_udp.py b/send_udp.py index 4b08f241..cc31349c 100755 --- a/send_udp.py +++ b/send_udp.py @@ -1,8 +1,9 @@ #!/usr/bin/python import socket +import os -UDP_IP = '127.0.0.1' -UDP_PORT = 21324 +UDP_IP = os.getenv('TREZOR_UDP_IP', '127.0.0.1') +UDP_PORT = int(os.getenv('TREZOR_UDP_PORT', '21324')) MESSAGE = b'Hello, World!' sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)