summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--hal/phy/maximus/src/maximus_pbdma.c11
-rw-r--r--hal/phy/maximus/src/maximus_phy_access.c28
-rw-r--r--hal/phy/maximus/src/maximus_phy_ctrl.c342
-rw-r--r--hal/phy/maximus/src/maximus_tmdma.c13
-rw-r--r--hal/phy/maximus/test/Config2
-rw-r--r--hal/phy/maximus/test/src/test_phy_ctrl.c93
-rw-r--r--host/station.h1
7 files changed, 325 insertions, 165 deletions
diff --git a/hal/phy/maximus/src/maximus_pbdma.c b/hal/phy/maximus/src/maximus_pbdma.c
index 3a02c5dff2..8c75ac4e4e 100644
--- a/hal/phy/maximus/src/maximus_pbdma.c
+++ b/hal/phy/maximus/src/maximus_pbdma.c
@@ -34,10 +34,12 @@ phy_pbdma_start (phy_t *ctx, bool bypass_aes, const u32 iv[3],
const u32 nek[4], uint nb_total, uint nb_ready,
uint nb_pb_it, phy_pb_t *first_pb)
{
+ dbg_assert_ptr(ctx);
+ dbg_assert_ptr(first_pb);
if ((NULL == ctx)
|| (NULL == first_pb))
{
- errno = EINVAL;
+ errno = EINVAL;
}
else
{
@@ -64,6 +66,10 @@ phy_pbdma_start (phy_t *ctx, bool bypass_aes, const u32 iv[3],
void
phy_pbdma_update (phy_t *ctx, uint nb_ready, uint nb_pb_it)
{
+ dbg_assert_ptr(ctx);
+ dbg_assert(nb_ready >= ctx->pb_dma.nb_ready);
+ dbg_assert(nb_pb_it <= ctx->pb_dma.nb_total);
+ dbg_assert(nb_ready <= ctx->pb_dma.nb_total);
if ((NULL == ctx)
|| (nb_ready < ctx->pb_dma.nb_ready)
|| (nb_pb_it > ctx->pb_dma.nb_total)
@@ -90,6 +96,9 @@ phy_pbdma_update (phy_t *ctx, uint nb_ready, uint nb_pb_it)
void
phy_pbdma_start_chandata (phy_t *ctx, phy_chandata_t *first_chandata)
{
+ dbg_assert_ptr(ctx);
+ dbg_assert_ptr(first_chandata);
+ dbg_assert(0 != first_chandata->type);
if ((NULL == ctx)
|| (NULL == first_chandata)
|| (0 == first_chandata->type)) // (INTERFACE TO BE UPDATED)
diff --git a/hal/phy/maximus/src/maximus_phy_access.c b/hal/phy/maximus/src/maximus_phy_access.c
index 8d043ad717..dd88f81cf1 100644
--- a/hal/phy/maximus/src/maximus_phy_access.c
+++ b/hal/phy/maximus/src/maximus_phy_access.c
@@ -31,7 +31,8 @@ extern uint32_t maximus_pending_isrs;
void maximus_phy_access_backoff_cb (void *data)
{
/* At the corresponding event reception, this function is called with the given cap as argument. */
-
+
+ dbg_assert_ptr(data);
if (NULL == data)
{
errno = EINVAL;
@@ -40,6 +41,7 @@ void maximus_phy_access_backoff_cb (void *data)
{
maximus_phy_access_backoff_t *access_backoff_data = (maximus_phy_access_backoff_t*)data;
+ dbg_assert_ptr(access_backoff_data->ctx);
if (NULL == access_backoff_data->ctx)
{
errno = EINVAL;
@@ -168,6 +170,7 @@ void maximus_phy_access_backoff_cb (void *data)
void
maximus_phy_access_slot_count_cb (void *data)
{
+ dbg_assert_ptr(data);
if (NULL == data)
{
errno = EINVAL;
@@ -214,6 +217,7 @@ maximus_phy_access_slot_count_cb (void *data)
void
maximus_phy_access_prs0_cb (void *data)
{
+ dbg_assert_ptr(data);
if (NULL == data)
{
errno = EINVAL;
@@ -317,6 +321,7 @@ maximus_phy_access_prs0_cb (void *data)
void
maximus_phy_access_prs1_cb (void *data)
{
+ dbg_assert_ptr(data);
if (NULL == data)
{
errno = EINVAL;
@@ -358,6 +363,7 @@ void maximus_phy_access_timer_cb (void *data)
/* If no PRE has been received, PHY raises an IT_ACCESS when access timer expires,
* i.e. this callback has to call the 'phy_access_cb'. */
+ dbg_assert_ptr(data);
if (NULL == data)
{
errno = EINVAL;
@@ -366,6 +372,8 @@ void maximus_phy_access_timer_cb (void *data)
{
maximus_phy_access_timer_t *access_timer_data = (maximus_phy_access_timer_t*)data;
+ dbg_assert_ptr(access_timer_data->ctx);
+ dbg_assert_ptr(access_timer_data->ctx->control.access_cb);
if ((NULL == access_timer_data->ctx)
|| (NULL == access_timer_data->ctx->control.access_cb))
{
@@ -403,7 +411,8 @@ phy_access_backoff_start (phy_t *ctx, u32 date, uint cap)
* defining a date to start PRP and giving the CAP. */
static maximus_phy_access_backoff_t cb_data;
-
+
+ dbg_assert_ptr(ctx);
if (NULL == ctx)
{
errno = EINVAL;
@@ -450,7 +459,8 @@ phy_access_backoff_update (phy_t *ctx, uint cap)
* - if this occurs before the PRP, the new CAP can be used without any other precaution;
* - if this occurs during the PRS0, the new CAP can change the PRS1 only (if the new CAP is higher than the old one, the PRS1 will be 1, if it is lower, the PRS1 will be 0);
* - if this occurs after the PRS0, the CAP can not be changed. */
-
+
+ dbg_assert_ptr(ctx);
if (NULL == ctx)
{
errno = EINVAL;
@@ -494,7 +504,8 @@ phy_access_backoff_slot_count (phy_t *ctx)
* Return the slot_count value of PHY context. */
uint slot_count = 0;
-
+
+ dbg_assert_ptr(ctx);
if (NULL == ctx)
{
errno = EINVAL;
@@ -522,7 +533,8 @@ phy_access_backoff_prp_won (phy_t *ctx)
* Return the prp_result value of PHY context. */
bool prp_result = false;
-
+
+ dbg_assert_ptr(ctx);
if (NULL == ctx)
{
errno = EINVAL;
@@ -549,7 +561,8 @@ phy_access_timer_program (phy_t *ctx, u32 date)
/* CA programs the access timer in order to precise the date at which CA decides to prepare its Tx. */
static maximus_phy_access_timer_t cb_data;
-
+
+ dbg_assert_ptr(ctx);
if (NULL == ctx)
{
errno = EINVAL;
@@ -588,7 +601,8 @@ void
phy_access_timer_cancel (phy_t *ctx)
{
/* When modem is stopped, CA cancels the access timer. */
-
+
+ dbg_assert_ptr(ctx);
if(NULL == ctx)
{
errno = EINVAL;
diff --git a/hal/phy/maximus/src/maximus_phy_ctrl.c b/hal/phy/maximus/src/maximus_phy_ctrl.c
index 7efc700433..93adf6db3f 100644
--- a/hal/phy/maximus/src/maximus_phy_ctrl.c
+++ b/hal/phy/maximus/src/maximus_phy_ctrl.c
@@ -18,6 +18,7 @@
#include "hal/phy/maximus/inc/maximus_phy_ctrl.h"
#include "hal/phy/maximus/inc/maximus_interrupts.h"
#include "hal/phy/maximus/inc/maximus_dur.h"
+#include <netinet/in.h> // for 'ntohl'
#include <string.h> // for 'memset'
#include <errno.h>
@@ -43,6 +44,7 @@ maximus_phy_tx_fc_cb (void *data)
{
static maximus_phy_tx_frame_t tx_frame_cb_data;
+ dbg_assert_ptr(data);
if (NULL == data)
{
errno = EINVAL;
@@ -51,6 +53,7 @@ maximus_phy_tx_fc_cb (void *data)
{
maximus_phy_tx_fc_t *tx_fc_data = (maximus_phy_tx_fc_t*)data;
+ dbg_assert_ptr(tx_fc_data->ctx);
if (NULL == tx_fc_data->ctx)
{
errno = EINVAL;
@@ -77,124 +80,123 @@ maximus_phy_tx_fc_cb (void *data)
uint32_t tick_high, tick_low;
tick_t schedule_tick;
- if (tx_fc_data->want_conf
- && ((MAXIMUS_PHY_MEDIUM_BUSY != tx_fc_data->ctx->access.medium_state)
- || !tx_fc_data->ctx->control.rx_tx_mode))
+ if ( (MAXIMUS_PHY_MEDIUM_BUSY != tx_fc_data->ctx->access.medium_state)
+ || !tx_fc_data->ctx->control.rx_tx_mode )
{
- if ((*tx_fc_data->ctx->control.access_conf_cb)(tx_fc_data->ctx->control.user_data))
+ if ( (tx_fc_data->want_conf)
+ &&((*tx_fc_data->ctx->control.access_conf_cb)(tx_fc_data->ctx->control.user_data)) )
{
// a DSR is requested
(*tx_fc_data->ctx->control.deferred_cb)(tx_fc_data->ctx->control.user_data);
}
-
- }
- // update medium state
- tx_fc_data->ctx->access.medium_state = MAXIMUS_PHY_MEDIUM_BUSY;
+ // update medium state
+ tx_fc_data->ctx->access.medium_state = MAXIMUS_PHY_MEDIUM_BUSY;
+
+ // set tx mode
+ tx_fc_data->ctx->control.rx_tx_mode = false;
+
+ // deactivate preamble detection
+ tx_fc_data->ctx->control.pre_detection = false;
- // set tx mode
- tx_fc_data->ctx->control.rx_tx_mode = false;
+ /* Then, this callback has to send a phy message containing fc_av
+ * (and fc_10 in Hybrid Mode). */
+
+ // init for phy message
+ memset(tx_fc_data->ctx->buffer, '\0', SCI_MSG_MAX_SIZE);
- // deactivate preamble detection
- tx_fc_data->ctx->control.pre_detection = false;
+ if (0 == sci_msg_init(&msg, tx_fc_data->ctx->buffer, SCI_MSG_MAX_SIZE))
+ {
+ // for phy header
+ uint8_t type = PHY_TYPE_FC_HYBRID_MODE;
+ uint8_t flags = PHY_FLAG_CRC_OK;
+ uint32_t nek[4];
+ uint32_t pb_measurement[PHY_PB_MAX_NB];
+ uint32_t pb_header[PHY_PB_MAX_NB];
+
+ // set phy header values
+ memset(nek, '\0', 4*sizeof(uint32_t));
+ memset(pb_measurement, '\0', PHY_PB_MAX_NB*sizeof(uint32_t));
+ memset(pb_header, '\0', PHY_PB_MAX_NB*sizeof(uint32_t));
+ if ((PHY_FC_MODE_AV_1 == tx_fc_data->ctx->control.fc_mode)
+ || (PHY_FC_MODE_AV_2 == tx_fc_data->ctx->control.fc_mode))
+ {
+ type = PHY_TYPE_FC_AV_ONLY_MODE;
+ }
+ if (PHY_PB_SIZE_520 == tx_fc_data->ctx->pb_dma.pb_size)
+ {
+ flags &= PHY_FLAG_PB512;
+ }
+
+ // fill sci data
+ if (4*sizeof(u32) == sci_msg_push(&msg, 4*sizeof(u32)))
+ {
+ memcpy(msg.data_begin, tx_fc_data->ctx->control.fc_av, 4*sizeof(u32));
+ }
+ if ((PHY_TYPE_FC_HYBRID_MODE == type)
+ && (sizeof(u32) == sci_msg_push(&msg, sizeof(u32))))
+ {
+ memcpy(msg.data_begin, &tx_fc_data->ctx->control.fc_10, sizeof(u32));
+ }
+
+ // fill phy header
+ maximus_phy_fill_hdr(tx_fc_data->ctx,
+ &msg,
+ type,
+ PHY_MPDU_FORMAT_NONE,
+ 0, // pb_nb
+ (uint8_t)tx_fc_data->ctx->tm_dma.tonemap_index,
+ flags,
+ nek,
+ pb_measurement,
+ pb_header);
- /* Then, this callback has to send a phy message containing fc_av
- * (and fc_10 in Hybrid Mode). */
-
- // init for phy message
- memset(tx_fc_data->ctx->buffer, '\0', SCI_MSG_MAX_SIZE);
+ // fill the sci header
+ sci_fill_hdr(my_station.sci, &msg, SCI_MSG_TYPE_PHY, 0 /* flags */);
- if (0 == sci_msg_init(&msg, tx_fc_data->ctx->buffer, SCI_MSG_MAX_SIZE))
- {
- // for phy header
- uint8_t type = PHY_TYPE_FC_HYBRID_MODE;
- uint8_t flags = PHY_FLAG_CRC_OK;
- uint32_t nek[4];
- uint32_t pb_measurement[PHY_PB_MAX_NB];
- uint32_t pb_header[PHY_PB_MAX_NB];
-
- // set phy header values
- memset(nek, '\0', 4*sizeof(uint32_t));
- memset(pb_measurement, '\0', PHY_PB_MAX_NB*sizeof(uint32_t));
- memset(pb_header, '\0', PHY_PB_MAX_NB*sizeof(uint32_t));
- if ((PHY_FC_MODE_AV_1 == tx_fc_data->ctx->control.fc_mode)
- || (PHY_FC_MODE_AV_2 == tx_fc_data->ctx->control.fc_mode))
- {
- type = PHY_TYPE_FC_AV_ONLY_MODE;
- }
- if (PHY_PB_SIZE_520 == tx_fc_data->ctx->pb_dma.pb_size)
- {
- flags &= PHY_FLAG_PB512;
- }
-
- // fill sci data
- if (4*sizeof(u32) == sci_msg_push(&msg, 4*sizeof(u32)))
- {
- memcpy(msg.data_begin, tx_fc_data->ctx->control.fc_av, 4*sizeof(u32));
- }
- if ((PHY_TYPE_FC_HYBRID_MODE == type)
- && (sizeof(u32) == sci_msg_push(&msg, sizeof(u32))))
- {
- memcpy(msg.data_begin, &tx_fc_data->ctx->control.fc_10, sizeof(u32));
+ // send the message
+ sci_send(my_station.sci, &msg);
}
- // fill phy header
- maximus_phy_fill_hdr(tx_fc_data->ctx,
- &msg,
- type,
- PHY_MPDU_FORMAT_NONE,
- 0, // pb_nb
- (uint8_t)tx_fc_data->ctx->tm_dma.tonemap_index,
- flags,
- nek,
- pb_measurement,
- pb_header);
-
- // fill the sci header
- sci_fill_hdr(my_station.sci, &msg, SCI_MSG_TYPE_PHY, 0 /* flags */);
+ if (!tx_fc_data->ctx->control.short_ppdu)
+ {
+ /* At last, to simulate the transmission time, this callback has to send a netclock message
+ * scheduled at a date calculated depending on PB number, modulation and guard interval. */
+
+ // calculate frame control transimission time
+ bits_per_symbol = maximus_dur_bits_per_symbol(tx_fc_data->ctx->tm_dma.mod,
+ tx_fc_data->ctx->tm_dma.tonemask,
+ tx_fc_data->ctx->tm_dma.tonemap[tx_fc_data->ctx->tm_dma.tonemap_index],
+ tx_fc_data->ctx->tm_dma.carrier_nb); // 4 bits per carrier
+ if ((PHY_FC_MODE_HYBRID_2 == tx_fc_data->ctx->control.fc_mode)
+ || (PHY_FC_MODE_AV_2 == tx_fc_data->ctx->control.fc_mode))
+ {
+ symbol_nb = 2;
+ }
+ duration_in_ticks = maximus_dur_data_tck(tx_fc_data->ctx->tm_dma.gil, symbol_nb);
- // send the message
- sci_send(my_station.sci, &msg);
- }
-
- if (!tx_fc_data->ctx->control.short_ppdu)
- {
- /* At last, to simulate the transmission time, this callback has to send a netclock message
- * scheduled at a date calculated depending on PB number, modulation and guard interval. */
+ // set schedule time
+ tick_high = my_station.current_tick_tck >> 32;
+ tick_low = (uint32_t)my_station.current_tick_tck + duration_in_ticks;
+ schedule_tick = (((unsigned long long)(tick_high)) << 32) | (unsigned long long)(tick_low);
- // calculate frame control transimission time
- bits_per_symbol = maximus_dur_bits_per_symbol(tx_fc_data->ctx->tm_dma.mod,
- tx_fc_data->ctx->tm_dma.tonemask,
- tx_fc_data->ctx->tm_dma.tonemap[tx_fc_data->ctx->tm_dma.tonemap_index],
- tx_fc_data->ctx->tm_dma.carrier_nb); // 4 bits per carrier
- if ((PHY_FC_MODE_HYBRID_2 == tx_fc_data->ctx->control.fc_mode)
- || (PHY_FC_MODE_AV_2 == tx_fc_data->ctx->control.fc_mode))
+ // fill callback data
+ tx_frame_cb_data.isr = tx_fc_data->isr;
+ tx_frame_cb_data.ctx = tx_fc_data->ctx;
+
+ netclock_schedule(my_station.netclock,
+ tx_fc_data->ctx->control.tx_frame_netclock_cb,
+ NETWORK_CLOCK_TYPE_STATION,
+ schedule_tick,
+ &maximus_phy_tx_frame_cb,
+ (void*)&tx_frame_cb_data,
+ &id);
+ }
+ else
{
- symbol_nb = 2;
+ // once phy message has been sent, set medium state to idle
+ tx_fc_data->ctx->access.medium_state = MAXIMUS_PHY_MEDIUM_IDLE;
}
- duration_in_ticks = maximus_dur_data_tck(tx_fc_data->ctx->tm_dma.gil, symbol_nb);
-
- // set schedule time
- tick_high = my_station.current_tick_tck >> 32;
- tick_low = (uint32_t)my_station.current_tick_tck + duration_in_ticks;
- schedule_tick = (((unsigned long long)(tick_high)) << 32) | (unsigned long long)(tick_low);
-
- // fill callback data
- tx_frame_cb_data.isr = tx_fc_data->isr;
- tx_frame_cb_data.ctx = tx_fc_data->ctx;
-
- netclock_schedule(my_station.netclock,
- tx_fc_data->ctx->control.tx_frame_netclock_cb,
- NETWORK_CLOCK_TYPE_STATION,
- schedule_tick,
- &maximus_phy_tx_frame_cb,
- (void*)&tx_frame_cb_data,
- &id);
- }
- else
- {
- // once phy message has been sent, set medium state to idle
- tx_fc_data->ctx->access.medium_state = MAXIMUS_PHY_MEDIUM_IDLE;
}
}
}
@@ -211,6 +213,7 @@ maximus_phy_tx_frame_cb (void *data)
/* At the corresponding event reception, the transfer really starts,
* i.e. this callback has to send a phy message containing MPDU payload. */
+ dbg_assert_ptr(data);
if (NULL == data)
{
errno = EINVAL;
@@ -219,6 +222,8 @@ maximus_phy_tx_frame_cb (void *data)
{
maximus_phy_tx_frame_t *tx_frame_data = (maximus_phy_tx_frame_t*)data;
+ dbg_assert_ptr(tx_frame_data->ctx);
+ dbg_assert_ptr(tx_frame_data->ctx->control.pbdma_cb);
if ((NULL == tx_frame_data->ctx)
|| (NULL == tx_frame_data->ctx->control.pbdma_cb))
{
@@ -413,6 +418,7 @@ maximus_phy_send_tonemap_cb (void *data)
/* At the corresponding event reception, the transfer really starts,
* i.e. this callback has to send a phy message containing tonemap. */
+ dbg_assert_ptr(data);
if (NULL == data)
{
errno = EINVAL;
@@ -511,6 +517,7 @@ maximus_phy_send_noise_cb (void *data)
/* At the corresponding event reception, the transfer really starts,
* i.e. this callback has to send a phy message containing frequency noise and time noise. */
+ dbg_assert_ptr(data);
if (NULL == data)
{
errno = EINVAL;
@@ -636,6 +643,7 @@ maximus_phy_send_spectrum_cb (void *data)
/* At the corresponding event reception, the transfer really starts,
* i.e. this callback has to send a phy message containing spectrum. */
+ dbg_assert_ptr(data);
if (NULL == data)
{
errno = EINVAL;
@@ -758,6 +766,7 @@ maximus_phy_rx_activate_cb (void *data)
{
/* This callback has to set ctx->control.pre_detection with the pre_detection value given as argument. */
+ dbg_assert_ptr(data);
if (NULL == data)
{
errno = EINVAL;
@@ -766,6 +775,7 @@ maximus_phy_rx_activate_cb (void *data)
{
maximus_phy_rx_activate_t *rx_activate_data = (maximus_phy_rx_activate_t*)data;
+ dbg_assert_ptr(rx_activate_data->ctx);
if (NULL == rx_activate_data->ctx)
{
errno = EINVAL;
@@ -806,6 +816,15 @@ maximus_phy_fill_hdr(phy_t *ctx,
{
int ret = -1;
+ dbg_assert_ptr(ctx);
+ dbg_assert_ptr(msg);
+ dbg_assert(PHY_TYPE_NB > type);
+ dbg_assert(PHY_MPDU_FORMAT_NB > mpdu_format);
+ dbg_assert(PHY_PB_MAX_NB >= pb_nb);
+ dbg_assert((PHY_FLAG_ENCRYPTED + PHY_FLAG_CRC_OK + PHY_FLAG_PB512) >= flags);
+ dbg_assert_ptr(nek);
+ dbg_assert_ptr(pb_measurement);
+ dbg_assert_ptr(pb_header);
if ((NULL == ctx)
|| (NULL == msg)
|| (PHY_TYPE_NB <= type)
@@ -860,6 +879,8 @@ maximus_phy_recv (sci_msg_t *msg, void *phy)
phy_t *ctx;
phy_msg_hdr_t phy_hdr;
+ dbg_assert_ptr(msg);
+ dbg_assert_ptr(phy);
if((NULL == msg) || (NULL == phy))
{
errno = EINVAL;
@@ -876,6 +897,15 @@ maximus_phy_recv (sci_msg_t *msg, void *phy)
/* Check phy header. */
+ dbg_assert_ptr(msg->hdr.phy);
+ dbg_assert(PHY_TYPE_NB > msg->hdr.phy->type);
+ dbg_assert(PHY_MPDU_FORMAT_NB > msg->hdr.phy->mpdu_format);
+ dbg_assert(PHY_PB_MAX_NB >= msg->hdr.phy->pb_nb);
+ dbg_assert(PHY_TONEMAP_MAX_NB > msg->hdr.phy->tonemap_index);
+ dbg_assert((PHY_FLAG_ENCRYPTED + PHY_FLAG_CRC_OK + PHY_FLAG_PB512) >= msg->hdr.phy->flags);
+ dbg_assert_ptr(msg->hdr.phy->nek);
+ dbg_assert_ptr(msg->hdr.phy->pb_measurement);
+ dbg_assert_ptr(msg->hdr.phy->pb_header);
if ((NULL == msg->hdr.phy)
|| (PHY_TYPE_NB <= msg->hdr.phy->type)
|| (PHY_MPDU_FORMAT_NB <= msg->hdr.phy->mpdu_format)
@@ -887,6 +917,8 @@ maximus_phy_recv (sci_msg_t *msg, void *phy)
|| (NULL == msg->hdr.phy->pb_header))
{
errno = EPROTO;
+ station_log(&my_station, STATION_LOG_ERROR, STATION_LOGTYPE_PHY,
+ "%s EPROTO", __FUNCTION__);
}
else
{
@@ -923,6 +955,9 @@ int
maximus_phy_recv_none (phy_t *ctx, sci_msg_t *msg)
{
errno = EPROTO;
+ station_log(&my_station, STATION_LOG_ERROR, STATION_LOGTYPE_PHY,
+ "%s EPROTO", __FUNCTION__);
+
return 0;
}
@@ -934,6 +969,10 @@ maximus_phy_recv_fc_hybrid_mode (phy_t *ctx, sci_msg_t *msg)
int ret = -1;
+ dbg_assert_ptr(ctx);
+ dbg_assert_ptr(msg);
+ dbg_assert_ptr(msg->sci_hdr);
+ dbg_assert_ptr(ctx->control.rx_fc_cb);
if((NULL == ctx)
|| (NULL == msg)
|| (NULL == msg->sci_hdr)
@@ -954,17 +993,20 @@ maximus_phy_recv_fc_hybrid_mode (phy_t *ctx, sci_msg_t *msg)
ctx->access.prp_result = false;
- // update medium state
- ctx->access.medium_state = MAXIMUS_PHY_MEDIUM_BUSY;
-
- // set rx mode
- ctx->control.rx_tx_mode = true;
+ if (!ctx->control.short_ppdu)
+ {
+ // update medium state
+ ctx->access.medium_state = MAXIMUS_PHY_MEDIUM_BUSY;
+
+ // set rx mode
+ ctx->control.rx_tx_mode = true;
+
+ // deactivate preamble detection
+ ctx->control.pre_detection = false;
+ }
- // deactivate preamble detection
- ctx->control.pre_detection = false;
-
// PHY raises an IT_RX_FC by calling 'phy_rx_fc_cb'
- if ((*ctx->control.rx_fc_cb)(ctx->control.user_data, msg->sci_hdr->netclock_low, ctx->control.fc_av))
+ if ((*ctx->control.rx_fc_cb)(ctx->control.user_data, ntohl(msg->sci_hdr->netclock_low), ctx->control.fc_av))
{
// a DSR is requested
(*ctx->control.deferred_cb)(ctx->control.user_data);
@@ -984,6 +1026,10 @@ maximus_phy_recv_fc_av_only_mode (phy_t *ctx, sci_msg_t *msg)
int ret = -1;
+ dbg_assert_ptr(ctx);
+ dbg_assert_ptr(msg);
+ dbg_assert_ptr(msg->sci_hdr);
+ dbg_assert_ptr(ctx->control.rx_fc_cb);
if((NULL == ctx)
|| (NULL == msg)
|| (NULL == msg->sci_hdr)
@@ -1002,17 +1048,20 @@ maximus_phy_recv_fc_av_only_mode (phy_t *ctx, sci_msg_t *msg)
ctx->access.prp_result = false;
- // update medium state
- ctx->access.medium_state = MAXIMUS_PHY_MEDIUM_BUSY;
-
- // set rx mode
- ctx->control.rx_tx_mode = true;
+ if (!ctx->control.short_ppdu)
+ {
+ // update medium state
+ ctx->access.medium_state = MAXIMUS_PHY_MEDIUM_BUSY;
+
+ // set rx mode
+ ctx->control.rx_tx_mode = true;
+
+ // deactivate preamble detection
+ ctx->control.pre_detection = false;
+ }
- // deactivate preamble detection
- ctx->control.pre_detection = false;
-
// PHY raises an IT_RX_FC by calling 'phy_rx_fc_cb'
- if ((*ctx->control.rx_fc_cb)(ctx->control.user_data, msg->sci_hdr->netclock_low, ctx->control.fc_av))
+ if ((*ctx->control.rx_fc_cb)(ctx->control.user_data, ntohl(msg->sci_hdr->netclock_low), ctx->control.fc_av))
{
// a DSR is requested
(*ctx->control.deferred_cb)(ctx->control.user_data);
@@ -1028,7 +1077,9 @@ int
maximus_phy_recv_prs (phy_t *ctx, sci_msg_t *msg)
{
int ret = -1;
-
+
+ dbg_assert_ptr(ctx);
+ dbg_assert_ptr(msg);
if((NULL == ctx) || (NULL == msg))
{
errno = EINVAL;
@@ -1045,6 +1096,8 @@ maximus_phy_recv_prs (phy_t *ctx, sci_msg_t *msg)
if (1 < prs)
{
errno = EPROTO;
+ station_log(&my_station, STATION_LOG_ERROR, STATION_LOGTYPE_PHY,
+ "%s EPROTO", __FUNCTION__);
}
else
{
@@ -1077,6 +1130,8 @@ maximus_phy_recv_mpdu_payload (phy_t *ctx, sci_msg_t *msg)
{
int ret = -1;
+ dbg_assert_ptr(ctx);
+ dbg_assert_ptr(msg);
if((NULL == ctx) || (NULL == msg))
{
errno = EINVAL;
@@ -1089,6 +1144,8 @@ maximus_phy_recv_mpdu_payload (phy_t *ctx, sci_msg_t *msg)
&& (0 == msg->hdr.phy->pb_nb)))
{
errno = EPROTO;
+ station_log(&my_station, STATION_LOG_ERROR, STATION_LOGTYPE_PHY,
+ "%s EPROTO", __FUNCTION__);
}
else
{
@@ -1181,6 +1238,10 @@ maximus_phy_recv_tonemap (phy_t *ctx, sci_msg_t *msg)
{
int ret = -1;
+ dbg_assert_ptr(ctx);
+ dbg_assert_ptr(msg);
+ dbg_assert(2 == msg->hdr.phy->pb_nb);
+ dbg_assert(PHY_TONEMAP_MAX_NB > msg->hdr.phy->tonemap_index);
if((NULL == ctx) || (NULL == msg))
{
errno = EINVAL;
@@ -1189,6 +1250,8 @@ maximus_phy_recv_tonemap (phy_t *ctx, sci_msg_t *msg)
|| (PHY_TONEMAP_MAX_NB <= msg->hdr.phy->tonemap_index))
{
errno = EPROTO;
+ station_log(&my_station, STATION_LOG_ERROR, STATION_LOGTYPE_PHY,
+ "%s EPROTO", __FUNCTION__);
}
else
{
@@ -1211,6 +1274,8 @@ maximus_phy_recv_noise (phy_t *ctx, sci_msg_t *msg)
{
int ret = -1;
+ dbg_assert_ptr(ctx);
+ dbg_assert_ptr(msg);
if((NULL == ctx) || (NULL == msg))
{
errno = EINVAL;
@@ -1266,7 +1331,9 @@ maximus_phy_recv_noise (phy_t *ctx, sci_msg_t *msg)
}
else
{
- errno = EPROTO;
+ errno = EPROTO;
+ station_log(&my_station, STATION_LOG_ERROR, STATION_LOGTYPE_PHY,
+ "%s EPROTO", __FUNCTION__);
}
}
sci_msg_pop(msg, PHY_CARRIER_NB*sizeof(uint16_t));
@@ -1281,6 +1348,9 @@ maximus_phy_recv_spectrum (phy_t *ctx, sci_msg_t *msg)
{
int ret = -1;
+ dbg_assert_ptr(ctx);
+ dbg_assert_ptr(msg);
+ dbg_assert_ptr(msg->hdr.phy);
if((NULL == ctx) || (NULL == msg) || (NULL == msg->hdr.phy))
{
errno = EINVAL;
@@ -1329,7 +1399,9 @@ maximus_phy_recv_spectrum (phy_t *ctx, sci_msg_t *msg)
}
else
{
- errno = EPROTO;
+ errno = EPROTO;
+ station_log(&my_station, STATION_LOG_ERROR, STATION_LOGTYPE_PHY,
+ "%s EPROTO", __FUNCTION__);
}
}
sci_msg_pop(msg, PHY_CARRIER_NB*sizeof(uint64_t));
@@ -1374,7 +1446,13 @@ phy_init (void *user_data, phy_rx_fc_cb_t rx_fc_cb, phy_access_cb_t access_cb,
static blk_t phy_tonemap[2*PHY_TONEMAP_MAX_NB]; // each tonemap uses two blocks
static u8 phy_tonemap1_data[PHY_PB_MAX_SIZE][PHY_TONEMAP_MAX_NB];
static u8 phy_tonemap2_data[PHY_CARRIER_NB/2-PHY_PB_MAX_SIZE][PHY_TONEMAP_MAX_NB]; // 4 bits per carrier
-
+
+ dbg_assert_ptr(user_data);
+ dbg_assert_ptr(rx_fc_cb);
+ dbg_assert_ptr(access_cb);
+ dbg_assert_ptr(access_conf_cb);
+ dbg_assert_ptr(pbdma_cb);
+ dbg_assert_ptr(deferred_cb);
if ((NULL == user_data)
|| (NULL == rx_fc_cb)
|| (NULL == access_cb)
@@ -1433,6 +1511,7 @@ phy_reset (phy_t *ctx)
/* After an error detection, PBP can reset the HW to a known sane state.
* Stop Tx/Rx and set PHY context to its initial values. */
+ dbg_assert_ptr(ctx);
if (NULL == ctx)
{
errno = EINVAL;
@@ -1478,6 +1557,7 @@ phy_uninit (phy_t *ctx)
* when modem is deactivated/reactivated.
* Stop Tx/Rx, set PHY context to NULL values. */
+ dbg_assert_ptr(ctx);
if (NULL == ctx)
{
errno = EINVAL;
@@ -1501,7 +1581,8 @@ phy_date (phy_t *ctx)
/* Return the current_date value of PHY context. */
u32 date = 0;
-
+
+ dbg_assert_ptr(ctx);
if (NULL == ctx)
{
errno = EINVAL;
@@ -1527,7 +1608,8 @@ phy_tx_fc10 (phy_t *ctx, u32 fc_10)
* PBP calls this function for HP 1.0 FC encoding
* 25µs before the start date given into 'phy_tx_frame'.
* Set the fc_10 value of PHY context. */
-
+
+ dbg_assert_ptr(ctx);
if (NULL == ctx)
{
errno = EINVAL;
@@ -1566,7 +1648,9 @@ phy_tx_param (phy_t *ctx, phy_fc_mode_t fc_mode, bool short_ppdu,
* Set the pb_size value of PHY context.
* Set the gil value of PHY context.
* Set the tonemap_index value of PHY context. */
-
+
+ dbg_assert_ptr(ctx);
+ dbg_assert(PHY_TONEMAP_MAX_NB > tonemap_index);
if ((NULL == ctx)
|| (PHY_TONEMAP_MAX_NB <= tonemap_index))
{
@@ -1616,6 +1700,7 @@ phy_tx_frame (phy_t *ctx, u32 date, bool want_conf, bool stop_tx_on_prp_lost,
* Set the fc_av[4] value of PHY context.
* Send a netclock message to Maximus simulator scheduled at the given date. */
+ dbg_assert_ptr(ctx);
if (NULL == ctx)
{
errno = EINVAL;
@@ -1708,6 +1793,7 @@ phy_rx_param (phy_t *ctx, phy_fc_mode_t fc_mode)
{
/* Set the fc_mode value of station context. */
+ dbg_assert_ptr(ctx);
if (NULL == ctx)
{
errno = EINVAL;
@@ -1738,6 +1824,7 @@ phy_rx_activate (phy_t *ctx, bool now, u32 date, bool pre_detection)
* - when a Tx starts (i.e. at the start date defined into 'phy_tx_frame').
* If PHY deactivates Rx, PBP has to reactivate it. */
+ dbg_assert_ptr(ctx);
if (NULL == ctx)
{
errno = EINVAL;
@@ -1808,6 +1895,7 @@ phy_rx_prepare (phy_t *ctx, bool short_ppdu, phy_mod_t mod,
* Set the tonemap_index value of PHY context.
* Set the symbol_nb value of PHY context. */
+ dbg_assert_ptr(ctx);
if (NULL == ctx)
{
errno = EINVAL;
diff --git a/hal/phy/maximus/src/maximus_tmdma.c b/hal/phy/maximus/src/maximus_tmdma.c
index 7e7c221fbe..1d610ffbaf 100644
--- a/hal/phy/maximus/src/maximus_tmdma.c
+++ b/hal/phy/maximus/src/maximus_tmdma.c
@@ -29,7 +29,9 @@ phy_set_tonemask (phy_t *ctx, u8 *tonemask, uint carrier_nb)
{
/* Set the carrier_nb value of PHY context.
* Copy tonemask contents into PHY context. */
-
+
+ dbg_assert_ptr(ctx);
+ dbg_assert_ptr(tonemask);
if ((NULL == ctx)
|| (NULL == tonemask))
{
@@ -59,7 +61,14 @@ phy_set_tonemap (phy_t *ctx, uint tonemap_index, blk_t *tonemap)
{
/* Set the tonemap_index value of PHY context.
* Copy tonemap contents into PHY context. */
-
+
+ dbg_assert_ptr(ctx);
+ dbg_assert(PHY_TONEMAP_MAX_NB > tonemap_index);
+ dbg_assert_ptr(tonemap);
+ dbg_assert_ptr(tonemap->next);
+ dbg_assert_ptr(tonemap->data);
+ dbg_assert(NULL == tonemap->next->next);
+ dbg_assert_ptr(tonemap->next->data);
if ((NULL == ctx)
|| (PHY_TONEMAP_MAX_NB <= tonemap_index)
|| (NULL == tonemap)
diff --git a/hal/phy/maximus/test/Config b/hal/phy/maximus/test/Config
new file mode 100644
index 0000000000..5077dbafd3
--- /dev/null
+++ b/hal/phy/maximus/test/Config
@@ -0,0 +1,2 @@
+CONFIG_DEBUG = y
+CONFIG_DEBUG_FATAL_CATCH = y
diff --git a/hal/phy/maximus/test/src/test_phy_ctrl.c b/hal/phy/maximus/test/src/test_phy_ctrl.c
index 13d001ca1c..08f4b2f713 100644
--- a/hal/phy/maximus/test/src/test_phy_ctrl.c
+++ b/hal/phy/maximus/test/src/test_phy_ctrl.c
@@ -89,17 +89,27 @@ void maximus_phy_fill_hdr_test_case(test_t t)
test_begin(t, "fill hdr with incorrect flags")
{
flags = 0x08;
- test_fail_unless ((-1 == maximus_phy_fill_hdr(ctx,
- &msg,
- type,
- mpdu_format,
- pb_nb,
- tonemap_index,
- flags,
- nek,
- pb_measurement,
- pb_header))
- && (EINVAL == errno));
+
+ dbg_fatal_try_begin
+ {
+ test_fail_unless ((-1 == maximus_phy_fill_hdr(ctx,
+ &msg,
+ type,
+ mpdu_format,
+ pb_nb,
+ tonemap_index,
+ flags,
+ nek,
+ pb_measurement,
+ pb_header))
+ && (EINVAL == errno));
+ }
+ dbg_fatal_try_catch (const char *fatal_message)
+ {
+ printf("fill hdr with incorrect flags\n%s\n", fatal_message);
+ }
+ dbg_fatal_try_end;
+
// reset errno
errno = 0;
} test_end;
@@ -108,17 +118,27 @@ void maximus_phy_fill_hdr_test_case(test_t t)
{
flags = 0x00;
pb_nb = 200;
- test_fail_unless ((-1 == maximus_phy_fill_hdr(ctx,
- &msg,
- type,
- mpdu_format,
- pb_nb,
- tonemap_index,
- flags,
- nek,
- pb_measurement,
- pb_header))
- && (EINVAL == errno));
+
+ dbg_fatal_try_begin
+ {
+ test_fail_unless ((-1 == maximus_phy_fill_hdr(ctx,
+ &msg,
+ type,
+ mpdu_format,
+ pb_nb,
+ tonemap_index,
+ flags,
+ nek,
+ pb_measurement,
+ pb_header))
+ && (EINVAL == errno));
+ }
+ dbg_fatal_try_catch (const char *fatal_message)
+ {
+ printf("fill hdr with incorrect number of PBs\n%s\n", fatal_message);
+ }
+ dbg_fatal_try_end;
+
// reset errno
errno = 0;
} test_end;
@@ -156,17 +176,34 @@ void maximus_phy_recv_test_case(test_t t)
test_begin(t, "NULL msg")
{
- test_fail_unless ((0 > (maximus_phy_recv(NULL, ctx)))
- && (EINVAL == errno));
-
+ dbg_fatal_try_begin
+ {
+ test_fail_unless ((0 > (maximus_phy_recv(NULL, ctx)))
+ && (EINVAL == errno));
+ }
+ dbg_fatal_try_catch (const char *fatal_message)
+ {
+ printf("NULL msg\n%s\n", fatal_message);
+ }
+ dbg_fatal_try_end;
+
// reset errno
errno = 0;
} test_end;
test_begin(t, "NULL phy")
- {
- test_fail_unless ((0 > (maximus_phy_recv(&msg, NULL)))
- && (EINVAL == errno));
+ {
+ dbg_fatal_try_begin
+ {
+ test_fail_unless ((0 > (maximus_phy_recv(&msg, NULL)))
+ && (EINVAL == errno));
+ }
+ dbg_fatal_try_catch (const char *fatal_message)
+ {
+ printf("NULL phy\n%s\n", fatal_message);
+ }
+ dbg_fatal_try_end;
+
// reset errno
errno = 0;
} test_end;
diff --git a/host/station.h b/host/station.h
index c81a1304f9..0a2feda3a1 100644
--- a/host/station.h
+++ b/host/station.h
@@ -68,6 +68,7 @@ typedef enum
#define STATION_LOGTYPE_SCI 0x00000008
#define STATION_LOGTYPE_PROBE 0x00000010
#define STATION_LOGTYPE_MISC 0x00000020
+#define STATION_LOGTYPE_PHY 0x00000040
#define STATION_LOGTYPE_ALL 0xffffffff
/** station context structure to manage a station process */