summaryrefslogtreecommitdiff
path: root/cleopatre/devkit/plcd/src/plcd_stack.c
diff options
context:
space:
mode:
Diffstat (limited to 'cleopatre/devkit/plcd/src/plcd_stack.c')
-rw-r--r--cleopatre/devkit/plcd/src/plcd_stack.c175
1 files changed, 124 insertions, 51 deletions
diff --git a/cleopatre/devkit/plcd/src/plcd_stack.c b/cleopatre/devkit/plcd/src/plcd_stack.c
index b4737233a6..7e8f10e590 100644
--- a/cleopatre/devkit/plcd/src/plcd_stack.c
+++ b/cleopatre/devkit/plcd/src/plcd_stack.c
@@ -452,32 +452,49 @@ plcd_send_recv_single_value (const plcd_ctx_t *ctx,
return 0;
}
-int
-plcd_stack_set_mac_address (const plcd_ctx_t *ctx, const unsigned char *mac_addr)
+/**
+ * Send DRV_STA_MAC_ADDR.REQ and receive DRV_STA_MAC_ADDR.CNF.
+ *
+ * \param ctx plcd context
+ * \return -1 on error, 0 otherwise
+ */
+static int
+plcd_stack_set_mac_address (const plcd_ctx_t *ctx)
{
PLCD_ASSERT (NULL != ctx);
- PLCD_ASSERT (NULL != mac_addr);
+ PLCD_ASSERT (ctx->nvram);
return plcd_send_recv_single_value (ctx, DRV_STA_SET_MAC_ADDR_REQ,
- mac_addr, ETH_ALEN);
+ ctx->nvram->plc_address, ETH_ALEN);
}
-int
-plcd_stack_set_cco_preferred (const plcd_ctx_t *ctx,
- libspid_boolean_t is_cco_preferred)
+/**
+ * Send DRV_STA_SET_CCO_PREF.REQ and receive DRV_STA_SET_CCO_PREF.CNF.
+ *
+ * \param ctx plcd context
+ * \return -1 on error, 0 otherwise
+ */
+static int
+plcd_stack_set_cco_preferred (const plcd_ctx_t *ctx)
{
- unsigned char value = (unsigned char) is_cco_preferred;
-
PLCD_ASSERT (NULL != ctx);
+ unsigned char value = (unsigned char) ctx->hpav_conf.is_cco_preferred;
+
return plcd_send_recv_single_value (ctx, DRV_STA_SET_CCO_PREF_REQ, &value,
sizeof (value));
}
-int
-plcd_stack_set_was_cco (const plcd_ctx_t *ctx, libspid_boolean_t was_cco)
+/**
+ * Send DRV_STA_SET_WAS_CCO.REQ and receive DRV_STA_SET_WAS_CCO.CNF.
+ *
+ * \param ctx plcd context
+ * \return -1 on error, 0 otherwise
+ */
+static int
+plcd_stack_set_was_cco (const plcd_ctx_t *ctx)
{
- unsigned char value = (unsigned char) was_cco;
+ unsigned char value = (unsigned char) ctx->hpav_conf.was_cco;
PLCD_ASSERT (NULL != ctx);
@@ -486,20 +503,21 @@ plcd_stack_set_was_cco (const plcd_ctx_t *ctx, libspid_boolean_t was_cco)
}
int
-plcd_stack_set_key (const plcd_ctx_t *ctx, const char *nmk_str,
- const char *nid_str, const char *sl_str)
+plcd_stack_set_key (const plcd_ctx_t *ctx)
{
+ PLCD_ASSERT (NULL != ctx);
+
+ const char *nmk_str = ctx->hpav_conf.nmk_str;
+ const char *nid_str = ctx->hpav_conf.nid_str;
+ const char *sl_str = ctx->hpav_conf.sl_str;
+
unsigned char buffer_req_cnf[ETH_DATA_LEN] = {0};
mme_ctx_t request_ctx, confirm_ctx;
unsigned char result = 0;
unsigned int result_len = 0;
- unsigned char tx_type = 0, tx_nid[LIBSPID_HPAV_CONF_NID_BIN_LEN] = {0}, \
- tx_sl = 0, tx_nmk[LIBSPID_HPAV_CONF_NMK_BIN_LEN] = {0};
-
- PLCD_ASSERT (NULL != ctx);
- PLCD_ASSERT (NULL != nmk_str);
- PLCD_ASSERT (NULL != nid_str);
- PLCD_ASSERT (NULL != sl_str);
+ unsigned char tx_type = 0, tx_sl = 0,
+ tx_nid[LIBSPID_HPAV_CONF_NID_BIN_LEN] = {0},
+ tx_nmk[LIBSPID_HPAV_CONF_NMK_BIN_LEN] = {0};
/* init mme */
mme_init (&request_ctx, DRV_STA_SET_KEY | MME_REQ,
@@ -581,13 +599,21 @@ plcd_stack_set_key (const plcd_ctx_t *ctx, const char *nmk_str,
return 0;
}
-int
-plcd_stack_set_dak (const plcd_ctx_t *ctx, const char *dpw)
+/**
+ * Send DRV_STA_SET_DAK.REQ and receive DRV_STA_SET_DAK.CNF.
+ *
+ * \param ctx plcd context
+ * \return -1 on error, 0 otherwise
+ */
+static int
+plcd_stack_set_dak (const plcd_ctx_t *ctx)
{
unsigned char dak[LIBSPID_SECU_OUTPUT_KEY_SIZE];
PLCD_ASSERT (NULL != ctx);
- PLCD_ASSERT (NULL != dpw);
+ PLCD_ASSERT (ctx->nvram);
+
+ const char *dpw = ctx->nvram->device_password;
/* firstly compute DAK from DPW */
if (LIBSPID_SUCCESS != libspid_secu_pbkdf1 (dpw, strlen (dpw),
@@ -603,44 +629,74 @@ plcd_stack_set_dak (const plcd_ctx_t *ctx, const char *dpw)
LIBSPID_SECU_OUTPUT_KEY_SIZE);
}
-int
-plcd_stack_set_manu_hfid (const plcd_ctx_t *ctx, const char *manu_hfid)
+/**
+ * Send DRV_STA_SET_M_STA_HFID.REQ and receive DRV_STA_SET_M_STA_HFID.CNF.
+ *
+ * \param ctx plcd context
+ * \return -1 on error, 0 otherwise
+ */
+static int
+plcd_stack_set_manu_hfid (const plcd_ctx_t *ctx)
{
PLCD_ASSERT (NULL != ctx);
- PLCD_ASSERT (NULL != manu_hfid);
+ PLCD_ASSERT (ctx->nvram);
+
+ const char *manu_hfid = ctx->nvram->product_name;
return plcd_send_recv_single_value (ctx, DRV_STA_SET_M_STA_HFID_REQ,
manu_hfid,
LIBSPID_HPAV_CONF_HFID_MAX_LEN);
}
-int
-plcd_stack_set_user_hfid (const plcd_ctx_t *ctx, const char *user_hfid)
+/**
+ * Send DRV_STA_SET_U_STA_HFID.REQ and receive DRV_STA_SET_U_STA_HFID.CNF.
+ *
+ * \param ctx plcd context
+ * \return -1 on error, 0 otherwise
+ */
+static int
+plcd_stack_set_user_hfid (const plcd_ctx_t *ctx)
{
PLCD_ASSERT (NULL != ctx);
- PLCD_ASSERT (NULL != user_hfid);
+
+ const char *user_hfid = ctx->hpav_conf.user_hfid;
return plcd_send_recv_single_value (ctx, DRV_STA_SET_U_STA_HFID,
user_hfid,
LIBSPID_HPAV_CONF_HFID_MAX_LEN);
}
-int
-plcd_stack_set_avln_hfid (const plcd_ctx_t *ctx, const char *avln_hfid)
+/**
+ * Send DRV_STA_SET_AVLN_HFID.REQ and receive DRV_STA_SET_AVLN_HFID.CNF.
+ *
+ * \param ctx plcd context
+ * \return -1 on error, 0 otherwise
+ */
+static int
+plcd_stack_set_avln_hfid (const plcd_ctx_t *ctx)
{
PLCD_ASSERT (NULL != ctx);
- PLCD_ASSERT (NULL != avln_hfid);
+
+ const char *avln_hfid = ctx->hpav_conf.avln_hfid;
return plcd_send_recv_single_value (ctx, DRV_STA_SET_AVLN_HFID,
avln_hfid,
LIBSPID_HPAV_CONF_HFID_MAX_LEN);
}
-int
-plcd_stack_set_tonemask (const plcd_ctx_t *ctx, const unsigned char *tonemask)
+/**
+ * Send DRV_STA_SET_TONEMASK.REQ and receive DRV_STA_SET_TONEMASK.CNF.
+ *
+ * \param ctx plcd context
+ * \return -1 on error, 0 otherwise
+ */
+static int
+plcd_stack_set_tonemask (const plcd_ctx_t *ctx)
{
PLCD_ASSERT (NULL != ctx);
- PLCD_ASSERT (NULL != tonemask);
+ PLCD_ASSERT (ctx->nvram);
+
+ const unsigned char *tonemask = ctx->nvram->tonemask;
return plcd_send_recv_single_value (ctx, DRV_STA_SET_TONEMASK,
tonemask, 192);
@@ -751,7 +807,14 @@ plcd_stack_set_config (const plcd_ctx_t *ctx, const char *file,
mme_buffer, strlen (mme_buffer) + 1);
}
-int
+/**
+ * Send DRV_STA_SET_CONFIG.REQ with contents of phy.conf file,
+ * and receive DRV_STA_SET_CONFIG.CNF.
+ *
+ * \param ctx plcd context
+ * \return -1 on error, 0 otherwise
+ */
+static int
plcd_stack_set_phy (const plcd_ctx_t *ctx)
{
const char *limit[] = {
@@ -762,13 +825,26 @@ plcd_stack_set_phy (const plcd_ctx_t *ctx)
return plcd_stack_set_config (ctx, ctx->phy_conf_path, limit);
}
-int
+/**
+ * Send DRV_STA_SET_CONFIG.REQ with contents of internal.conf file,
+ * and receive DRV_STA_SET_CONFIG.CNF.
+ *
+ * \param ctx plcd context
+ * \return -1 on error, 0 otherwise
+ */
+static int
plcd_stack_set_internal (const plcd_ctx_t *ctx)
{
return plcd_stack_set_config (ctx, ctx->internal_conf_path, NULL);
}
-int
+/**
+ * Send DRV_STA_MAC_START.REQ and receive DRV_STA_MAC_START.CNF.
+ *
+ * \param ctx plcd context
+ * \return -1 on error, 0 otherwise
+ */
+static int
plcd_stack_start (const plcd_ctx_t *ctx)
{
PLCD_ASSERT (NULL != ctx);
@@ -780,68 +856,65 @@ int
plcd_stack_init (const plcd_ctx_t *ctx)
{
PLCD_ASSERT (NULL != ctx);
- PLCD_ASSERT (NULL != ctx->nvram);
/* send MAC address to AV / EoC stack */
- if(0 > plcd_stack_set_mac_address (ctx, ctx->nvram->plc_address))
+ if(0 > plcd_stack_set_mac_address (ctx))
{
syslog (LOG_WARNING, "stack set mac address failed");
return -1;
}
/* send CCO_PREFERRED to AV / EoC stack */
- if (0 > plcd_stack_set_cco_preferred (ctx, ctx->hpav_conf.is_cco_preferred))
+ if (0 > plcd_stack_set_cco_preferred (ctx))
{
syslog (LOG_WARNING, "stack set cco preferred failed");
return -1;
}
/* send WAS_CCO to AV / EoC stack */
- if (0 > plcd_stack_set_was_cco (ctx, ctx->hpav_conf.was_cco))
+ if (0 > plcd_stack_set_was_cco (ctx))
{
syslog (LOG_WARNING, "stack set was cco failed");
return -1;
}
/* send NMK and (NID or SL) */
- if (0 > plcd_stack_set_key (ctx, ctx->hpav_conf.nmk_str,
- ctx->hpav_conf.nid_str,
- ctx->hpav_conf.sl_str))
+ if (0 > plcd_stack_set_key (ctx))
{
syslog (LOG_WARNING, "stack set key failed");
return -1;
}
/* send DAK */
- if (0 > plcd_stack_set_dak (ctx, ctx->nvram->device_password))
+ if (0 > plcd_stack_set_dak (ctx))
{
syslog (LOG_WARNING, "stack set dak failed");
return -1;
}
/* send manufacturer HFID */
- if (0 > plcd_stack_set_manu_hfid (ctx, ctx->nvram->product_name))
+ if (0 > plcd_stack_set_manu_hfid (ctx))
{
syslog (LOG_WARNING, "stack set manu hfid failed");
return -1;
}
/* send user HFID */
- if (0 > plcd_stack_set_user_hfid (ctx, ctx->hpav_conf.user_hfid))
+ if (0 > plcd_stack_set_user_hfid (ctx))
{
syslog (LOG_WARNING, "stack set user hfid failed");
return -1;
}
/* send AVLN HFID */
- if (0 > plcd_stack_set_avln_hfid (ctx, ctx->hpav_conf.avln_hfid))
+ if (0 > plcd_stack_set_avln_hfid (ctx))
{
syslog (LOG_WARNING, "stack set avln hfid failed");
return -1;
}
/* send tonemask */
- if (0 > plcd_stack_set_tonemask (ctx, ctx->nvram->tonemask))
+ if (0 > plcd_stack_set_tonemask (ctx))
{
syslog (LOG_WARNING, "stack set tonemask failed");
return -1;