summaryrefslogtreecommitdiff
path: root/cesar/interface
diff options
context:
space:
mode:
authorlaranjeiro2008-06-18 07:37:32 +0000
committerlaranjeiro2008-06-18 07:37:32 +0000
commit8054526700962edcc165aa3008693667e014b01c (patch)
tree22d0ff1df4fc1ad593144adce0cd65fe1d87eeed /cesar/interface
parent60d5f3abb5acfd78c0a23bcd770c893c0ebf16e7 (diff)
interface: Added the call back in the interface/fcall module to get a buffer to send a answer.
git-svn-id: svn+ssh://pessac/svn/cesar/trunk@2369 017c9cb6-072f-447c-8318-d5b54f68fe89
Diffstat (limited to 'cesar/interface')
-rw-r--r--cesar/interface/fcall/inc/context.h12
-rw-r--r--cesar/interface/fcall/interface_fcall.h6
-rw-r--r--cesar/interface/fcall/src/interface_fcall.c18
-rw-r--r--cesar/interface/fcall/test/src/test_interface_fcall.c26
-rw-r--r--cesar/interface/inc/interface.h2
-rw-r--r--cesar/interface/interface.h7
-rw-r--r--cesar/interface/src/interface.c51
7 files changed, 76 insertions, 46 deletions
diff --git a/cesar/interface/fcall/inc/context.h b/cesar/interface/fcall/inc/context.h
index e997af40e8..aa11403a28 100644
--- a/cesar/interface/fcall/inc/context.h
+++ b/cesar/interface/fcall/inc/context.h
@@ -10,7 +10,7 @@
/**
* \file interface/fcall/inc/context.h
* \brief Context of the interface fcall module.
- * \ingroup interface/fcall
+ * \ingroup interface/fcall
*
*/
#include "host/fcall/fcall.h"
@@ -20,6 +20,13 @@ typedef void (*interface_fcall_send_message_cb_t) (void *user_data, uint *messag
typedef void (*interface_fcall_send_done_message_cb_t) (void *user_data, u8 *message);
+/** Get a buffer to send answer.
+ * \param user_data the user data previously registered.
+ * \return buffer the buffer provided.
+ */
+typedef u8 *
+(*interface_fcall_get_buffer_cb_t) (void *user_data);
+
typedef struct interface_fcall_t
{
fcall_ctx_t *fcall_ctx; /** pointer to fcall context */
@@ -30,6 +37,9 @@ typedef struct interface_fcall_t
bitstream_t bitstream_ctx; /** bitstream context */
mac_t oda; /** ODA of the received MME */
mac_t osa; /** OSA of the received MME */
+
+ /** interface_fcall_get_buffer call back*/
+ interface_fcall_get_buffer_cb_t buffer_get_cb;
} interface_fcall_t;
#endif /* interface_fcall_inc_context_h */
diff --git a/cesar/interface/fcall/interface_fcall.h b/cesar/interface/fcall/interface_fcall.h
index 8c1d7c0a1e..f683098ae1 100644
--- a/cesar/interface/fcall/interface_fcall.h
+++ b/cesar/interface/fcall/interface_fcall.h
@@ -10,7 +10,7 @@
/**
* \file interface/fcall/interface_fcall.h
* \brief Public interface fcall module functions.
- * \ingroup interface/fcall
+ * \ingroup interface/fcall
*
*/
#include "interface/fcall/inc/context.h"
@@ -19,11 +19,13 @@
* initialise the interface fcall module and the callback functions
* \param send_cb the function to call when the interface fcall needs to send an INTERFACE message
* \param send_done_cb the function to call when the interface fcall needs to send a SEND DONE message
+ * \param buffer_get_cb the function to call back to get a buffer.
* \param user_data the data to provide on callback function
*/
interface_fcall_t*
interface_fcall_init (interface_fcall_send_message_cb_t send_cb,
interface_fcall_send_done_message_cb_t send_done_cb,
+ interface_fcall_get_buffer_cb_t buffer_get_cb,
void *user_data);
/**
@@ -40,6 +42,6 @@ interface_fcall_uninit (interface_fcall_t *ctx);
* \param buffer an empty allocated buffer for fcall response
*/
void
-interface_fcall_mme_recv (void *data, u8 *mme, u8 *buffer);
+interface_fcall_mme_recv (void *data, u8 *mme);
#endif /* interface_fcall_interface_fcall_h */
diff --git a/cesar/interface/fcall/src/interface_fcall.c b/cesar/interface/fcall/src/interface_fcall.c
index 545eb8b3a0..b1eb6afaf7 100644
--- a/cesar/interface/fcall/src/interface_fcall.c
+++ b/cesar/interface/fcall/src/interface_fcall.c
@@ -29,11 +29,13 @@
* initialise the interface fcall module and the callback functions
* \param send_cb the function to call when the interface fcall needs to send an INTERFACE message
* \param send_done_cb the function to call when the interface fcall needs to send a SEND DONE message
+ * \param buffer_get_cb the function to call back to get a buffer.
* \param user_data the data to provide on callback function
*/
interface_fcall_t*
interface_fcall_init (interface_fcall_send_message_cb_t send_cb,
interface_fcall_send_done_message_cb_t send_done_cb,
+ interface_fcall_get_buffer_cb_t buffer_get_cb,
void *user_data)
{
static interface_fcall_t ctx;
@@ -43,10 +45,12 @@ interface_fcall_init (interface_fcall_send_message_cb_t send_cb,
dbg_assert_ptr(send_cb);
dbg_assert_ptr(send_done_cb);
+ dbg_assert_ptr(buffer_get_cb);
dbg_assert_ptr(user_data);
if ((NULL == send_cb)
|| (NULL == send_done_cb)
- || (NULL == user_data))
+ || (NULL == user_data)
+ || (NULL == buffer_get_cb))
{
errno = EINVAL;
return NULL;
@@ -57,6 +61,7 @@ interface_fcall_init (interface_fcall_send_message_cb_t send_cb,
ctx.probe_ctx = &probe_ctx;
ctx.send_cb = send_cb;
ctx.send_done_cb = send_done_cb;
+ ctx.buffer_get_cb = buffer_get_cb;
ctx.user_data = user_data;
#ifdef FCALL_PROTO
@@ -107,21 +112,19 @@ interface_fcall_uninit (interface_fcall_t *ctx)
* \param ctx the interface fcall context
* \param mme the MME buffer
* \param length the MME length
- * \param buffer an empty allocated buffer for fcall response
*/
void
-interface_fcall_mme_recv (void *data, u8 *mme, u8 *buffer)
+interface_fcall_mme_recv (void *data, u8 *mme)
{
interface_fcall_t *ctx = NULL;
static sci_msg_t msg;
uint length = 0;
+ u8 *buffer;
dbg_assert_ptr(data);
dbg_assert_ptr(mme);
- dbg_assert_ptr(buffer);
if ( (NULL == data)
- || (NULL == mme)
- || (NULL == buffer) )
+ || (NULL == mme))
{
errno = EINVAL;
return;
@@ -138,6 +141,9 @@ interface_fcall_mme_recv (void *data, u8 *mme, u8 *buffer)
/** Read payload length. */
length = read_u16_from_word(mme + INTERFACE_FCALL_PAYLOAD_OFFSET - sizeof(u16)) + INTERFACE_FCALL_PAYLOAD_OFFSET;
+ /** Get a buffer. */
+ buffer = (*ctx->buffer_get_cb) (ctx->user_data);
+
if (sci_msg_init(&msg, buffer, SCI_MSG_MAX_SIZE) < 0)
{
dbg_assert_print(false, "sci msg init failed with errno = %d", errno);
diff --git a/cesar/interface/fcall/test/src/test_interface_fcall.c b/cesar/interface/fcall/test/src/test_interface_fcall.c
index 3873126d3e..e538e6cd96 100644
--- a/cesar/interface/fcall/test/src/test_interface_fcall.c
+++ b/cesar/interface/fcall/test/src/test_interface_fcall.c
@@ -44,9 +44,15 @@ interface_fcall_send_done_message_cb (void *user_data, u8 *message)
return;
}
+u8 *
+interface_fcall_buffer_get (void *user_data)
+{
+ return NULL;
+}
+
int host_fcall_test (fcall_ctx_t *fcall, fcall_param_t **param, sci_msg_t **msg, void *data)
{
- return 0;
+ return 0;
}
void
@@ -62,8 +68,9 @@ interface_fcall_init_test_case(test_t t)
{
test_fail_unless(
(NULL == interface_fcall_init(NULL,
- &interface_fcall_send_done_message_cb,
- (void*)&user_data))
+ &interface_fcall_send_done_message_cb,
+ &interface_fcall_buffer_get,
+ (void*)&user_data))
);
}
dbg_fatal_try_catch (const char *fatal_message)
@@ -80,6 +87,7 @@ interface_fcall_init_test_case(test_t t)
test_fail_unless(
(NULL == interface_fcall_init(interface_fcall_send_message_cb,
NULL,
+ &interface_fcall_buffer_get,
(void*)&user_data))
);
}
@@ -96,7 +104,8 @@ interface_fcall_init_test_case(test_t t)
{
test_fail_unless(
(NULL == interface_fcall_init(&interface_fcall_send_message_cb,
- &interface_fcall_send_done_message_cb,
+ &interface_fcall_send_done_message_cb,
+ &interface_fcall_buffer_get,
NULL))
);
}
@@ -111,6 +120,7 @@ interface_fcall_init_test_case(test_t t)
{
ctx = interface_fcall_init(&interface_fcall_send_message_cb,
&interface_fcall_send_done_message_cb,
+ &interface_fcall_buffer_get,
(void*)&user_data);
test_fail_unless(
(NULL != ctx)
@@ -139,7 +149,7 @@ interface_fcall_mme_recv_test_case(test_t t)
{
dbg_fatal_try_begin
{
- interface_fcall_mme_recv (NULL, mme, buffer);
+ interface_fcall_mme_recv (NULL, mme);
}
dbg_fatal_try_catch (const char *fatal_message)
{
@@ -152,7 +162,7 @@ interface_fcall_mme_recv_test_case(test_t t)
{
dbg_fatal_try_begin
{
- interface_fcall_mme_recv (ctx, NULL, buffer);
+ interface_fcall_mme_recv (ctx, NULL);
}
dbg_fatal_try_catch (const char *fatal_message)
{
@@ -165,7 +175,7 @@ interface_fcall_mme_recv_test_case(test_t t)
{
dbg_fatal_try_begin
{
- interface_fcall_mme_recv (ctx, mme, NULL);
+ interface_fcall_mme_recv (ctx, mme);
}
dbg_fatal_try_catch (const char *fatal_message)
{
@@ -184,7 +194,7 @@ interface_fcall_mme_recv_test_case(test_t t)
memcpy((char*)mme + INTERFACE_FCALL_PAYLOAD_OFFSET - sizeof(u16), &length, sizeof(u16));
memcpy((char*)mme + INTERFACE_FCALL_PAYLOAD_OFFSET, &fcall_hdr, sizeof(fcall_hdr));
strcpy((char*)mme + INTERFACE_FCALL_PAYLOAD_OFFSET + sizeof(fcall_hdr), test);
- interface_fcall_mme_recv (ctx, mme, buffer);
+ interface_fcall_mme_recv (ctx, mme);
test_fail_unless(
(errno != EINVAL)
);
diff --git a/cesar/interface/inc/interface.h b/cesar/interface/inc/interface.h
index 5159fd30af..edee4ed024 100644
--- a/cesar/interface/inc/interface.h
+++ b/cesar/interface/inc/interface.h
@@ -47,7 +47,7 @@ interface_buffer_work_add (interface_t *ctx, u8 *buffer);
void
interface_hle_recv (interface_t *ctx, u8 *buffer);
-/**
+/**
* Get a buffer from the list.
* \param ctx the interface context.
* \return the buffer to use, NULL if no buffer is available.
diff --git a/cesar/interface/interface.h b/cesar/interface/interface.h
index e01e80ca88..1e06ad2700 100644
--- a/cesar/interface/interface.h
+++ b/cesar/interface/interface.h
@@ -10,7 +10,7 @@
/**
* \file interface/interface.h
* \brief Inteface module public functions.
- * \ingroup interface
+ * \ingroup interface
*
* The interface module allows the communication between Actors and
* the Data plane.
@@ -27,7 +27,7 @@
* and 1 buffer for fcall sub-module. */
#define INTERFACE_BUFFER_LIST_NUM_SLOTS 3
-/**
+/**
* Function to call when the interface receives a new MME.
* \param ctx the interface context
* \param mfs the mfs from the one the MF comes if it comes from the PWL.
@@ -49,7 +49,7 @@ typedef void
typedef void
(*interface_mme_buffer_add_cb_t) (void *user_data, u8 *buffer);
-/**
+/**
* Function to call when the interface receives a beacon.
* \param user_data the data registered by the actor in the init function.
* \param beacon the beacon freshly received.
@@ -58,7 +58,6 @@ typedef void
(*interface_beacon_add_cb_t) (void *user_data, pb_beacon_t *beacon);
-
/**
* Initialise the interface module.
* \param hle the hle context.
diff --git a/cesar/interface/src/interface.c b/cesar/interface/src/interface.c
index 89bc390ef4..9570ece135 100644
--- a/cesar/interface/src/interface.c
+++ b/cesar/interface/src/interface.c
@@ -8,7 +8,7 @@
/**
* \file interface/src/interface.c
* \brief Interface functions sources.
- * \ingroup interface
+ * \ingroup interface
*
*/
#include "common/std.h"
@@ -55,6 +55,7 @@ interface_init (hle_t *hle, cl_t *cl, sar_t *sar, mac_config_t
interface_global.fcall = interface_fcall_init
((interface_fcall_send_message_cb_t) interface_hle_send,
(interface_fcall_send_done_message_cb_t) interface_hle_send_done,
+ (interface_fcall_get_buffer_cb_t) interface_buffer_work_get,
&interface_global);
circular_buffer_init (&interface_global.buffers,
@@ -70,12 +71,15 @@ interface_init (hle_t *hle, cl_t *cl, sar_t *sar, mac_config_t
&interface_global);
// Integrate the CL.
- cl_mme_init_buffer_add_cb (cl,(cl_mme_buffer_add_cb_t) interface_buffer_add,
+ cl_mme_init_buffer_add_cb (cl,
+ (cl_mme_buffer_add_cb_t) interface_buffer_add,
&interface_global);
- cl_mme_recv_init (cl,(cl_mme_recv_cb_t) interface_mme_recv, &interface_global);
+ cl_mme_recv_init (cl,(cl_mme_recv_cb_t) interface_mme_recv,
+ &interface_global);
// Integrate the SAR.
- sar_init_beacon_cb (sar, &interface_global, (sar_beacon_cb_t) interface_beacon_add);
+ sar_init_beacon_cb (sar, &interface_global,
+ (sar_beacon_cb_t) interface_beacon_add);
// Create the mailbox.
cyg_mbox_create(&interface_global.mbox_handle, &interface_global.mailbox);
@@ -93,7 +97,7 @@ interface_init (hle_t *hle, cl_t *cl, sar_t *sar, mac_config_t
return &interface_global;
}
-/**
+/**
* Interface uninit.
* \param ctx the interface context.
*/
@@ -123,7 +127,7 @@ interface_callback_init (interface_t *ctx, interface_mme_recv_cb_t mme_recv_cb,
dbg_assert (ctx);
dbg_assert (mme_recv_cb);
dbg_assert (buffer_add_cb);
-
+
ctx->mme_recv_cb = mme_recv_cb;
ctx->buffer_add_cb = buffer_add_cb;
ctx->interface_mme_user_data = user_data;
@@ -137,7 +141,7 @@ interface_callback_init (interface_t *ctx, interface_mme_recv_cb_t mme_recv_cb,
* \param user_data the data to provide on each callback function.
*/
void
-interface_callback_beacon_init (interface_t *ctx,
+interface_callback_beacon_init (interface_t *ctx,
interface_beacon_add_cb_t beacon_add_cb,
void *user_data)
{
@@ -159,7 +163,7 @@ interface_callback_beacon_init (interface_t *ctx,
* crypted.
*/
void
-interface_mme_recv (interface_t *ctx, mfs_rx_t *mfs, u8 *buffer, uint length,
+interface_mme_recv (interface_t *ctx, mfs_rx_t *mfs, u8 *buffer, uint length,
cl_mme_recv_t *mme_data, bool encrypted)
{
u8 *copy_buffer;
@@ -206,7 +210,7 @@ interface_mme_recv_done (interface_t *ctx, void *mme_recv)
* \param ctx the interface context.
* \param buffer the buffer containing the MME.
* \param length the length of the MME.
- * \param mfs the MFS to send the MME if the mme is to be sent over the PWL,
+ * \param mfs the MFS to send the MME if the mme is to be sent over the PWL,
* otherwise this pointer is NULL.
*/
void
@@ -235,7 +239,7 @@ interface_mme_send (interface_t *ctx, u8* buffer, uint length, mfs_tx_t *mfs)
}
-/**
+/**
* Sends a beacon, the interface will provide it to the SAR.
* \param ctx the interface context.
* \param beacon the beacon to send.
@@ -258,7 +262,7 @@ interface_beacon_prepare (interface_t *ctx, pb_beacon_t *beacon, mac_t
if (interface_sniffer_beacon_status_tx (ctx->sniffer))
{
buffer = interface_buffer_work_get (ctx);
-
+
if (buffer)
{
interface_sniffer_copy_beacon_tx (ctx->sniffer, beacon, buffer,
@@ -299,7 +303,7 @@ void interface_beacon_add (interface_t *ctx, pb_beacon_t *pb,
}
dbg_assert (ctx->beacon_add_cb);
- (*ctx->beacon_add_cb) (ctx->beacon_user_data, pb);
+ (*ctx->beacon_add_cb) (ctx->beacon_user_data, pb);
}
@@ -323,7 +327,7 @@ interface_hle_send (interface_t *ctx, uint *data, uint length)
* Called by the interface fcall module when the buffer has been used.
* This allows the HLE to know which buffer is newly available to be used or
* give it back to the ARM. (the buffer is borrowed by the linux).
- *
+ *
* \param ctx the interface context.
* \param buffer the buffer used to send the data.
*/
@@ -365,14 +369,14 @@ interface_buffer_work_add (interface_t *ctx, u8 *buffer)
dbg_assert (buffer);
dbg_assert (ctx->buffer_add_cb);
-
+
/* Lock the mutex. */
cyg_mutex_lock (&ctx->buffer_mutex);
added = circular_buffer_add (&ctx->buffers, buffer);
cyg_mutex_unlock (&ctx->buffer_mutex);
}
-/**
+/**
* Get a buffer from the list.
* \param ctx the interface context.
* \return the buffer to use, NULL if no buffer is available.
@@ -425,7 +429,7 @@ interface_process (cyg_addrword_t data)
while (true)
{
if ((buffer = (u8 *) cyg_mbox_get(ctx->mbox_handle)))
- {
+ {
switch (interface_mmtype_get (buffer))
{
case DRV_INTERFACE_CONFIG_REQ:
@@ -436,9 +440,7 @@ interface_process (cyg_addrword_t data)
interface_sniffer_configure_and_respond (ctx, buffer);
break;
case INTERFACE_MODULE_FCALL:
- interface_fcall_mme_recv (ctx->fcall,
- buffer,
- interface_buffer_work_get(ctx));
+ interface_fcall_mme_recv (ctx->fcall, buffer);
break;
}
}
@@ -451,7 +453,7 @@ interface_process (cyg_addrword_t data)
* response of the configuration.
* \param ctx the interface context.
* \param buffer the MME buffer containing the data and use to response.
- *
+ *
* Provide the configuration byte to the sniffer sub module and reuse the
* buffer to create the confirm MME by replace the MMType and the payload by
* the ACK value.
@@ -474,16 +476,17 @@ interface_sniffer_configure_and_respond (interface_t *ctx, u8 *buffer)
interface_sniffer_configure (ctx->sniffer, read_u8_from_word (buffer + 0x15));
// Writing the answer.
-
+
mmtype = DRV_INTERFACE_CONFIG_CNF;
//Modify directly the MMTYPE.
- bitstream_init (&bitstream, buffer + 0xF, 2, BITSTREAM_WRITE);
+ bitstream_init (&bitstream, buffer + 0xF, 2, BITSTREAM_WRITE);
bitstream_access (&bitstream, &mmtype, 16);
bitstream_finalise (&bitstream);
// Add the SACK.
bitstream_init (&bitstream, buffer + 0x14, 1, BITSTREAM_WRITE);
- if (read_u8_from_word (buffer + 0x15) == interface_sniffer_status(ctx->sniffer))
+ if (read_u8_from_word (buffer + 0x15) ==
+ interface_sniffer_status(ctx->sniffer))
{
sack = true;
bitstream_access ( &bitstream, &sack, 8);
@@ -491,7 +494,7 @@ interface_sniffer_configure_and_respond (interface_t *ctx, u8 *buffer)
bitstream_finalise ( &bitstream);
word[0] = BF_FILL (IPMBOX_REG, (MSG_TYPE, HLE_MSG_TYPE_INTERFACE),
- (MSG_LENGTH, 1),
+ (MSG_LENGTH, 1),
(PARAM_INTERFACE_TYPE, INTERFACE_MODULE_SNIFFER),
(PARAM_INTERFACE_LENGTH, 60));