summaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
Diffstat (limited to 'src/core')
-rw-r--r--src/core/ao.h6
-rw-r--r--src/core/ao_aes.h17
-rw-r--r--src/core/ao_radio_cmac.c84
-rw-r--r--src/core/ao_radio_cmac.h43
4 files changed, 50 insertions, 100 deletions
diff --git a/src/core/ao.h b/src/core/ao.h
index 5e1fbb9d..b8bedd85 100644
--- a/src/core/ao.h
+++ b/src/core/ao.h
@@ -543,9 +543,6 @@ ao_telemetry_tiny_init(void);
*/
extern __xdata uint8_t ao_radio_dma;
-extern __xdata uint8_t ao_radio_dma_done;
-extern __xdata uint8_t ao_radio_done;
-extern __xdata uint8_t ao_radio_mutex;
#ifdef PKT_APPEND_STATUS_1_CRC_OK
#define AO_RADIO_STATUS_CRC_OK PKT_APPEND_STATUS_1_CRC_OK
@@ -566,6 +563,9 @@ ao_radio_recv(__xdata void *d, uint8_t size) __reentrant;
void
ao_radio_recv_abort(void);
+void
+ao_radio_test(uint8_t on);
+
/*
* Compute the packet length as follows:
*
diff --git a/src/core/ao_aes.h b/src/core/ao_aes.h
index ab3e367e..c47bc2db 100644
--- a/src/core/ao_aes.h
+++ b/src/core/ao_aes.h
@@ -51,21 +51,4 @@ ao_aes_run(__xdata uint8_t *in,
void
ao_aes_init(void);
-/* ao_radio_cmac.c */
-
-int8_t
-ao_radio_cmac_send(__xdata void *packet, uint8_t len) __reentrant;
-
-#define AO_RADIO_CMAC_OK 0
-#define AO_RADIO_CMAC_LEN_ERROR -1
-#define AO_RADIO_CMAC_CRC_ERROR -2
-#define AO_RADIO_CMAC_MAC_ERROR -3
-#define AO_RADIO_CMAC_TIMEOUT -4
-
-int8_t
-ao_radio_cmac_recv(__xdata void *packet, uint8_t len, uint16_t timeout) __reentrant;
-
-void
-ao_radio_cmac_init(void);
-
#endif /* _AO_AES_H_ */
diff --git a/src/core/ao_radio_cmac.c b/src/core/ao_radio_cmac.c
index 3e8dce53..fc0ca8b1 100644
--- a/src/core/ao_radio_cmac.c
+++ b/src/core/ao_radio_cmac.c
@@ -15,39 +15,15 @@
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
*/
-#include "ao.h"
-
-#define AO_CMAC_KEY_LEN AO_AES_LEN
-#define AO_CMAC_MAX_LEN (128 - AO_CMAC_KEY_LEN)
+#include <ao.h>
+#include <ao_radio_cmac.h>
static __xdata uint8_t ao_radio_cmac_mutex;
-__pdata int16_t ao_radio_cmac_rssi;
+__pdata int8_t ao_radio_cmac_rssi;
static __xdata uint8_t cmac_data[AO_CMAC_MAX_LEN + AO_CMAC_KEY_LEN + 2 + AO_CMAC_KEY_LEN];
static __pdata uint8_t ao_radio_cmac_len;
static uint8_t
-getnibble(void)
-{
- int8_t b;
-
- b = ao_cmd_hexchar(getchar());
- if (b < 0) {
- ao_cmd_status = ao_cmd_lex_error;
- return 0;
- }
- return (uint8_t) b;
-}
-
-static uint8_t
-getbyte(void)
-{
- uint8_t b;
- b = getnibble() << 4;
- b |= getnibble();
- return b;
-}
-
-static uint8_t
round_len(uint8_t len)
{
uint8_t rem;
@@ -120,7 +96,7 @@ radio_cmac_recv(uint8_t len, uint16_t timeout) __reentrant
return AO_RADIO_CMAC_TIMEOUT;
}
- ao_radio_cmac_rssi = (int16_t) (((int8_t) cmac_data[len + AO_CMAC_KEY_LEN]) >> 1) - 74;
+ ao_radio_cmac_rssi = (int8_t) (((int8_t) cmac_data[len + AO_CMAC_KEY_LEN]) >> 1) - 74;
if (!(cmac_data[len + AO_CMAC_KEY_LEN +1] & AO_RADIO_STATUS_CRC_OK))
return AO_RADIO_CMAC_CRC_ERROR;
@@ -191,55 +167,3 @@ ao_radio_cmac_recv(__xdata void *packet, uint8_t len, uint16_t timeout) __reentr
return i;
}
-static void
-radio_cmac_send_cmd(void) __reentrant
-{
- uint8_t i;
- uint8_t len;
-
- ao_cmd_decimal();
- if (ao_cmd_status != ao_cmd_success)
- return;
- len = ao_cmd_lex_i;
- if (len > AO_CMAC_MAX_LEN) {
- ao_cmd_status = ao_cmd_syntax_error;
- return;
- }
- flush();
- ao_mutex_get(&ao_radio_cmac_mutex);
- len = ao_cmd_lex_i;
- for (i = 0; i < len; i++) {
- cmac_data[i] = getbyte();
- if (ao_cmd_status != ao_cmd_success)
- return;
- }
- radio_cmac_send(len);
- ao_mutex_put(&ao_radio_cmac_mutex);
-}
-
-static void
-radio_cmac_recv_cmd(void) __reentrant
-{
- uint8_t len, i;
- uint16_t timeout;
-
- ao_cmd_decimal();
- if (ao_cmd_status != ao_cmd_success)
- return;
- len = ao_cmd_lex_i;
- ao_cmd_decimal();
- if (ao_cmd_status != ao_cmd_success)
- return;
- timeout = AO_MS_TO_TICKS(ao_cmd_lex_i);
- ao_mutex_get(&ao_radio_cmac_mutex);
- i = radio_cmac_recv(len, timeout);
- if (i == AO_RADIO_CMAC_OK) {
- printf ("PACKET ");
- for (i = 0; i < len; i++)
- printf("%02x", cmac_data[i]);
- printf (" %d\n", ao_radio_cmac_rssi);
- } else
- printf ("ERROR %d %d\n", i, ao_radio_cmac_rssi);
- ao_mutex_put(&ao_radio_cmac_mutex);
-}
-
diff --git a/src/core/ao_radio_cmac.h b/src/core/ao_radio_cmac.h
new file mode 100644
index 00000000..e86f31e9
--- /dev/null
+++ b/src/core/ao_radio_cmac.h
@@ -0,0 +1,43 @@
+/*
+ * Copyright © 2012 Keith Packard <keithp@keithp.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ */
+
+#ifndef _AO_RADIO_CMAC_H_
+#define _AO_RADIO_CMAC_H_
+
+#include <ao_aes.h>
+
+#define AO_CMAC_KEY_LEN AO_AES_LEN
+#define AO_CMAC_MAX_LEN (128 - AO_CMAC_KEY_LEN)
+
+extern __pdata int8_t ao_radio_cmac_rssi;
+
+int8_t
+ao_radio_cmac_send(__xdata void *packet, uint8_t len) __reentrant;
+
+#define AO_RADIO_CMAC_OK 0
+#define AO_RADIO_CMAC_LEN_ERROR -1
+#define AO_RADIO_CMAC_CRC_ERROR -2
+#define AO_RADIO_CMAC_MAC_ERROR -3
+#define AO_RADIO_CMAC_TIMEOUT -4
+
+int8_t
+ao_radio_cmac_recv(__xdata void *packet, uint8_t len, uint16_t timeout) __reentrant;
+
+void
+ao_radio_cmac_init(void);
+
+#endif /* _AO_RADIO_CMAC_H_ */