summaryrefslogtreecommitdiff
path: root/cleopatre/application/spidnetsnmp/agent
diff options
context:
space:
mode:
authorTom Yang2012-05-18 14:20:59 +0200
committerTom Yang2012-05-25 19:10:10 +0530
commitfb1a6dfacd1f2d1ad78eaee0415707de325a1070 (patch)
treef1ecc5bdb173103f116c1faff013f0844b714b77 /cleopatre/application/spidnetsnmp/agent
parent164ee344a9c921d2af9062a8a6bded757647ec5e (diff)
cleo/app/snmp[eoc]: implement the SoftwareUpgradeGroup, refs #3017
Conflicts: cleopatre/application/spidnetsnmp/agent/mibgroup/mstar-eoc-mib.h
Diffstat (limited to 'cleopatre/application/spidnetsnmp/agent')
-rw-r--r--cleopatre/application/spidnetsnmp/agent/mibgroup/mstar-eoc-mib.h3
-rw-r--r--cleopatre/application/spidnetsnmp/agent/mibgroup/mstar-eoc-mib/eocSoftwareUpgradeGroup.h4
-rw-r--r--cleopatre/application/spidnetsnmp/agent/mibgroup/mstar-eoc-mib/eocSoftwareUpgradeGroup/eocSoftwareUpgradeGroup.c897
-rw-r--r--cleopatre/application/spidnetsnmp/agent/mibgroup/mstar-eoc-mib/eocSoftwareUpgradeGroup/eocSoftwareUpgradeGroup.h6
-rw-r--r--cleopatre/application/spidnetsnmp/agent/mibgroup/mstar-eoc-mib/eocSoftwareUpgradeGroup/eocSoftwareUpgradeTable.h10
-rw-r--r--cleopatre/application/spidnetsnmp/agent/mibgroup/mstar-eoc-mib/eocSoftwareUpgradeGroup/eocSoftwareUpgradeTable/eocSoftwareUpgradeTable.h33
-rw-r--r--cleopatre/application/spidnetsnmp/agent/mibgroup/mstar-eoc-mib/eocSoftwareUpgradeGroup/eocSoftwareUpgradeTable/eocSoftwareUpgradeTable_data_access.c586
-rw-r--r--cleopatre/application/spidnetsnmp/agent/mibgroup/mstar-eoc-mib/eocSoftwareUpgradeGroup/eocSoftwareUpgradeTable/eocSoftwareUpgradeTable_data_set.c953
8 files changed, 1934 insertions, 558 deletions
diff --git a/cleopatre/application/spidnetsnmp/agent/mibgroup/mstar-eoc-mib.h b/cleopatre/application/spidnetsnmp/agent/mibgroup/mstar-eoc-mib.h
index 10451c925e..63c512f241 100644
--- a/cleopatre/application/spidnetsnmp/agent/mibgroup/mstar-eoc-mib.h
+++ b/cleopatre/application/spidnetsnmp/agent/mibgroup/mstar-eoc-mib.h
@@ -2,10 +2,9 @@ config_add_mib(NSCRTV-EPONEOC-MOD-EOC-MIB)
//config_require(mstar-eoc-mib/eocCBATAdminGroup)
config_require(mstar-eoc-mib/eocCBATCardRFGroup)
config_require(mstar-eoc-mib/eocCBATCardMACGroup)
-//config_require(mstar-eoc-mib/eocSoftwareUpgradeGroup)
+config_require(mstar-eoc-mib/eocSoftwareUpgradeGroup)
config_require(mstar-eoc-mib/eocCNUGroup)
config_require(mstar-eoc-mib/eocStatisticGroup)
-//config_require(mstar-eoc-mib/eocCBATCardMACGroup)
config_require(mstar-eoc-mib/eocTrapGroup)
config_require(mstar-eoc-mib/eocVLANGroup)
config_require(mstar-eoc-mib/eocBroadcastStormProtectionGroup)
diff --git a/cleopatre/application/spidnetsnmp/agent/mibgroup/mstar-eoc-mib/eocSoftwareUpgradeGroup.h b/cleopatre/application/spidnetsnmp/agent/mibgroup/mstar-eoc-mib/eocSoftwareUpgradeGroup.h
index 11c5a64e98..5171a31699 100644
--- a/cleopatre/application/spidnetsnmp/agent/mibgroup/mstar-eoc-mib/eocSoftwareUpgradeGroup.h
+++ b/cleopatre/application/spidnetsnmp/agent/mibgroup/mstar-eoc-mib/eocSoftwareUpgradeGroup.h
@@ -1,2 +1,2 @@
-//config_require(mstar-eoc-mib/eocSoftwareUpgradeGroup/eocSoftwareUpgradeTable)
-//config_require(mstar-eoc-mib/eocSoftwareUpgradeGroup/eocSoftwareUpgradeGroup)
+config_require(mstar-eoc-mib/eocSoftwareUpgradeGroup/eocSoftwareUpgradeTable)
+config_require(mstar-eoc-mib/eocSoftwareUpgradeGroup/eocSoftwareUpgradeGroup)
diff --git a/cleopatre/application/spidnetsnmp/agent/mibgroup/mstar-eoc-mib/eocSoftwareUpgradeGroup/eocSoftwareUpgradeGroup.c b/cleopatre/application/spidnetsnmp/agent/mibgroup/mstar-eoc-mib/eocSoftwareUpgradeGroup/eocSoftwareUpgradeGroup.c
index 0b19e1201b..b1176b6723 100644
--- a/cleopatre/application/spidnetsnmp/agent/mibgroup/mstar-eoc-mib/eocSoftwareUpgradeGroup/eocSoftwareUpgradeGroup.c
+++ b/cleopatre/application/spidnetsnmp/agent/mibgroup/mstar-eoc-mib/eocSoftwareUpgradeGroup/eocSoftwareUpgradeGroup.c
@@ -12,7 +12,7 @@
void
init_eocSoftwareUpgradeGroup(void)
{
- static oid eocSoftwaretUpgradeServerIP_oid[] = { 1,3,6,1,4,1,17409,2,4,4,1 };
+ static oid eocSoftwareUpgradeServerIP_oid[] = { 1,3,6,1,4,1,17409,2,4,4,1 };
static oid eocSoftwareUpgradeServerPort_oid[] = { 1,3,6,1,4,1,17409,2,4,4,2 };
static oid eocSoftwareUpgradeLogin_oid[] = { 1,3,6,1,4,1,17409,2,4,4,3 };
static oid eocSoftwareUpgradePassWord_oid[] = { 1,3,6,1,4,1,17409,2,4,4,4 };
@@ -20,8 +20,8 @@ init_eocSoftwareUpgradeGroup(void)
DEBUGMSGTL(("eocSoftwareUpgradeGroup", "Initializing\n"));
netsnmp_register_scalar(
- netsnmp_create_handler_registration("eocSoftwaretUpgradeServerIP", handle_eocSoftwaretUpgradeServerIP,
- eocSoftwaretUpgradeServerIP_oid, OID_LENGTH(eocSoftwaretUpgradeServerIP_oid),
+ netsnmp_create_handler_registration("eocSoftwareUpgradeServerIP", handle_eocSoftwareUpgradeServerIP,
+ eocSoftwareUpgradeServerIP_oid, OID_LENGTH(eocSoftwareUpgradeServerIP_oid),
HANDLER_CAN_RWRITE
));
netsnmp_register_scalar(
@@ -42,80 +42,193 @@ init_eocSoftwareUpgradeGroup(void)
}
int
-handle_eocSoftwaretUpgradeServerIP(netsnmp_mib_handler *handler,
+handle_eocSoftwareUpgradeServerIP(netsnmp_mib_handler *handler,
netsnmp_handler_registration *reginfo,
netsnmp_agent_request_info *reqinfo,
netsnmp_request_info *requests)
{
int ret;
+
+ char ip_addr[4];
+ char *ip_addr_save = NULL;
+ u_char *value;
+
+ char buffer[LIBSPID_LINE_MAX_LEN];
/* We are never called for a GETNEXT if it's registered as a
"instance", as it's "magically" handled for us. */
/* a instance handler also only hands us one request at a time, so
we don't need to loop over a list of requests; we'll only get one. */
-
- switch(reqinfo->mode) {
- case MODE_GET:
- snmp_set_var_typed_value(requests->requestvb, ASN_IPADDRESS,
- (u_char *) /* XXX: a pointer to the scalar's data */,
- /* XXX: the length of the data in bytes */);
- break;
+ switch (reqinfo->mode)
+ {
+ case MODE_GET:
+
+ /* read buffer for upgrade server IP address from config file */
+ ret = libspid_config_read_item (
+ LIBSPID_SYSTEM_CONF_PATH,
+ LIBSPID_SYSTEM_CONF_LABEL_UPGRADE_SERVER_IP,
+ buffer, LIBSPID_LINE_MAX_LEN);
+ if (LIBSPID_SUCCESS != ret)
+ {
+ snmp_log (LOG_ERR, "libspid_config_read_item error\n");
+ /* IP address set to 0.0.0.0 to permit walk requests */
+ memset (ip_addr, 0, 4);
+ }
+ else
+ {
+ /* convert IP address from string to array of bytes */
+ ret = libspid_ip_str_to_bin (buffer, ip_addr);
+ if (LIBSPID_SUCCESS != ret)
+ {
+ memset (ip_addr, 0, 4);
+ }
+ }
+ snmp_set_var_typed_value (requests->requestvb, ASN_IPADDRESS,
+ (u_char *) ip_addr, sizeof (ip_addr));
+ break;
/*
* SET REQUEST
*
* multiple states in the transaction. See:
- * http://www.net-snmp.org/tutorial-5/toolkit/mib_module/set-actions.jpg
+ * http://www.net-snmp.org/tutorial-5/toolkit/mib_module/
+ * set-actions.jpg
*/
- case MODE_SET_RESERVE1:
- /* or you could use netsnmp_check_vb_type_and_size instead */
- ret = netsnmp_check_vb_type(requests->requestvb, ASN_IPADDRESS);
- if ( ret != SNMP_ERR_NOERROR ) {
- netsnmp_set_request_error(reqinfo, requests, ret );
- }
- break;
-
- case MODE_SET_RESERVE2:
- /* XXX malloc "undo" storage buffer */
- if (/* XXX if malloc, or whatever, failed: */) {
- netsnmp_set_request_error(reqinfo, requests, SNMP_ERR_RESOURCEUNAVAILABLE);
- }
- break;
-
- case MODE_SET_FREE:
- /* XXX: free resources allocated in RESERVE1 and/or
- RESERVE2. Something failed somewhere, and the states
- below won't be called. */
- break;
-
- case MODE_SET_ACTION:
- /* XXX: perform the value change here */
- if (/* XXX: error? */) {
- netsnmp_set_request_error(reqinfo, requests, /* some error */);
- }
- break;
-
- case MODE_SET_COMMIT:
- /* XXX: delete temporary storage */
- if (/* XXX: error? */) {
- /* try _really_really_ hard to never get to this point */
- netsnmp_set_request_error(reqinfo, requests, SNMP_ERR_COMMITFAILED);
+ case MODE_SET_RESERVE1:
+ /* or you could use netsnmp_check_vb_type_and_size instead */
+ ret = netsnmp_check_vb_type (requests->requestvb, ASN_IPADDRESS);
+ if (ret != SNMP_ERR_NOERROR)
+ {
+ netsnmp_set_request_error (reqinfo, requests, ret);
+ }
+ break;
+
+ case MODE_SET_RESERVE2:
+ /*
+ * malloc "undo" storage buffer
+ */
+ /* read buffer for upgrade server IP address from config file */
+ ret = libspid_config_read_item (
+ LIBSPID_SYSTEM_CONF_PATH,
+ LIBSPID_SYSTEM_CONF_LABEL_UPGRADE_SERVER_IP,
+ buffer, LIBSPID_LINE_MAX_LEN);
+ if (LIBSPID_SUCCESS != ret)
+ {
+ snmp_log (LOG_ERR, "libspid_config_read_item error\n");
+ netsnmp_set_request_error (reqinfo, requests,
+ SNMP_ERR_RESOURCEUNAVAILABLE);
+ }
+ else
+ {
+ /* convert IP address from string to array of bytes */
+ ret = libspid_ip_str_to_bin (buffer, ip_addr);
+ if (LIBSPID_SUCCESS != ret)
+ {
+ memset (ip_addr, 0, 4);
}
- break;
+ }
+
+ memdup ((u_char **) & ip_addr_save, (u_char *) ip_addr,
+ sizeof (ip_addr));
+
+ if (NULL == ip_addr_save)
+ {
+ /* if malloc, or whatever, failed: */
+ netsnmp_set_request_error (reqinfo, requests,
+ SNMP_ERR_RESOURCEUNAVAILABLE);
+ }
+ else
+ {
+ netsnmp_request_add_list_data (requests,
+ netsnmp_create_data_list
+ ("upgradeserveripaddr",
+ ip_addr_save, free));
+ }
+ break;
+
+ case MODE_SET_FREE:
+ /*
+ * free resources allocated in RESERVE1 and/or
+ * RESERVE2. Something failed somewhere, and the states
+ * below won't be called.
+ */
+ free (ip_addr_save);
+ break;
- case MODE_SET_UNDO:
- /* XXX: UNDO and return to previous value for the object */
- if (/* XXX: error? */) {
- /* try _really_really_ hard to never get to this point */
- netsnmp_set_request_error(reqinfo, requests, SNMP_ERR_UNDOFAILED);
- }
- break;
+ case MODE_SET_ACTION:
+ /*
+ * perform the value change here
+ */
+ value = requests->requestvb->val.string;
+
+ /* convert IP address given in SET request from array of
+ bytes to string */
+ ret = libspid_ip_bin_to_str (value, buffer);
+ if (LIBSPID_SUCCESS != ret)
+ {
+ snmp_log (LOG_ERR, "libspid_ip_bin_to_str error\n");
+ netsnmp_set_request_error (reqinfo, requests,
+ SNMP_ERR_RESOURCEUNAVAILABLE);
+ }
+
+ /* store new IP data */
+ ret = libspid_config_write_item (
+ LIBSPID_SYSTEM_CONF_PATH,
+ LIBSPID_SYSTEM_CONF_LABEL_UPGRADE_SERVER_IP,
+ buffer);
+ if (LIBSPID_SUCCESS != ret)
+ {
+ snmp_log (LOG_ERR, "libspid_config_write_item error\n");
+ netsnmp_set_request_error (reqinfo, requests,
+ SNMP_ERR_COMMITFAILED);
+ }
+
+ break;
+
+ case MODE_SET_COMMIT:
+ /*
+ * delete temporary storage
+ */
+ free (ip_addr_save);
+ break;
- default:
- /* we should never get here, so this is a really bad error */
- snmp_log(LOG_ERR, "unknown mode (%d) in handle_eocSoftwaretUpgradeServerIP\n", reqinfo->mode );
- return SNMP_ERR_GENERR;
+ case MODE_SET_UNDO:
+ /*
+ * UNDO and return to previous value for the object
+ */
+ value =
+ (u_char *) netsnmp_request_get_list_data (requests,
+ "upgradeserveripaddr");
+ /* convert IP address from array of bytes to string */
+ ret = libspid_ip_bin_to_str (value, buffer);
+ if (LIBSPID_SUCCESS != ret)
+ {
+ snmp_log (LOG_ERR, "libspid_ip_bin_to_str error\n");
+ netsnmp_set_request_error (reqinfo, requests,
+ SNMP_ERR_RESOURCEUNAVAILABLE);
+ }
+
+ /* restore IP data */
+ ret = libspid_config_write_item (
+ LIBSPID_SYSTEM_CONF_PATH,
+ LIBSPID_SYSTEM_CONF_LABEL_UPGRADE_SERVER_IP,
+ buffer);
+ if (LIBSPID_SUCCESS != ret)
+ {
+ snmp_log (LOG_ERR, "libspid_config_write_item error\n");
+ netsnmp_set_request_error (reqinfo, requests,
+ SNMP_ERR_UNDOFAILED);
+ }
+
+ free (ip_addr_save);
+ break;
+
+ default:
+ /* we should never get here, so this is a really bad error */
+ snmp_log (LOG_ERR, "unknown mode (%d) in "
+ "handle_eocSoftwareUpgradeServerIP\n", reqinfo->mode);
+ return SNMP_ERR_GENERR;
}
return SNMP_ERR_NOERROR;
@@ -127,74 +240,166 @@ handle_eocSoftwareUpgradeServerPort(netsnmp_mib_handler *handler,
netsnmp_request_info *requests)
{
int ret;
- /* We are never called for a GETNEXT if it's registered as a
- "instance", as it's "magically" handled for us. */
- /* a instance handler also only hands us one request at a time, so
- we don't need to loop over a list of requests; we'll only get one. */
-
- switch(reqinfo->mode) {
-
- case MODE_GET:
- snmp_set_var_typed_value(requests->requestvb, ASN_INTEGER,
- (u_char *) /* XXX: a pointer to the scalar's data */,
- /* XXX: the length of the data in bytes */);
- break;
+ int server_port;
+ int *server_port_save = NULL;
+ u_long value;
+
+ char buffer[LIBSPID_LINE_MAX_LEN];
+
+ /*
+ * We are never called for a GETNEXT if it's registered as a
+ * "instance", as it's "magically" handled for us.
+ */
+
+ /*
+ * a instance handler also only hands us one request at a time, so
+ * we don't need to loop over a list of requests; we'll only get one.
+ */
+
+ switch (reqinfo->mode)
+ {
+ case MODE_GET:
+ /* read buffer for upgrade server port from config file */
+ ret = libspid_config_read_item (
+ LIBSPID_SYSTEM_CONF_PATH,
+ LIBSPID_SYSTEM_CONF_LABEL_UPGRADE_SERVER_PORT,
+ buffer, LIBSPID_LINE_MAX_LEN);
+ if (LIBSPID_SUCCESS != ret)
+ {
+ snmp_log (LOG_ERR, "libspid_config_read_item error\n");
+ /* port set to 0 permit walk requests */
+ server_port = 0;
+ }
+ else
+ {
+ /* parse port from buffer */
+ if (1 != sscanf (buffer, "%d", &server_port))
+ {
+ server_port = 0;
+ }
+ }
+ snmp_set_var_typed_value (requests->requestvb, ASN_INTEGER,
+ (u_char *) & server_port,
+ sizeof (server_port));
+ break;
/*
* SET REQUEST
*
* multiple states in the transaction. See:
- * http://www.net-snmp.org/tutorial-5/toolkit/mib_module/set-actions.jpg
+ * http://www.net-snmp.org/tutorial-5/toolkit/mib_module/
+ * set-actions.jpg
*/
- case MODE_SET_RESERVE1:
- /* or you could use netsnmp_check_vb_type_and_size instead */
- ret = netsnmp_check_vb_type(requests->requestvb, ASN_INTEGER);
- if ( ret != SNMP_ERR_NOERROR ) {
- netsnmp_set_request_error(reqinfo, requests, ret );
- }
- break;
-
- case MODE_SET_RESERVE2:
- /* XXX malloc "undo" storage buffer */
- if (/* XXX if malloc, or whatever, failed: */) {
- netsnmp_set_request_error(reqinfo, requests, SNMP_ERR_RESOURCEUNAVAILABLE);
- }
- break;
-
- case MODE_SET_FREE:
- /* XXX: free resources allocated in RESERVE1 and/or
- RESERVE2. Something failed somewhere, and the states
- below won't be called. */
- break;
-
- case MODE_SET_ACTION:
- /* XXX: perform the value change here */
- if (/* XXX: error? */) {
- netsnmp_set_request_error(reqinfo, requests, /* some error */);
+ case MODE_SET_RESERVE1:
+ /* or you could use netsnmp_check_vb_type_and_size instead */
+ ret = netsnmp_check_vb_type (requests->requestvb, ASN_INTEGER);
+ if (ret != SNMP_ERR_NOERROR)
+ {
+ netsnmp_set_request_error (reqinfo, requests, ret);
+ }
+ break;
+
+ case MODE_SET_RESERVE2:
+ /* read buffer for upgrade server port from config file */
+ ret = libspid_config_read_item (
+ LIBSPID_SYSTEM_CONF_PATH,
+ LIBSPID_SYSTEM_CONF_LABEL_UPGRADE_SERVER_PORT,
+ buffer, LIBSPID_LINE_MAX_LEN);
+ if (LIBSPID_SUCCESS != ret)
+ {
+ snmp_log (LOG_ERR, "libspid_config_read_item error\n");
+ netsnmp_set_request_error (reqinfo, requests,
+ SNMP_ERR_RESOURCEUNAVAILABLE);
+ }
+ else
+ {
+ /* parse port from buffer */
+ if (1 != sscanf (buffer, "%d", &server_port))
+ {
+ server_port = 0;
}
- break;
-
- case MODE_SET_COMMIT:
- /* XXX: delete temporary storage */
- if (/* XXX: error? */) {
- /* try _really_really_ hard to never get to this point */
- netsnmp_set_request_error(reqinfo, requests, SNMP_ERR_COMMITFAILED);
- }
- break;
-
- case MODE_SET_UNDO:
- /* XXX: UNDO and return to previous value for the object */
- if (/* XXX: error? */) {
- /* try _really_really_ hard to never get to this point */
- netsnmp_set_request_error(reqinfo, requests, SNMP_ERR_UNDOFAILED);
- }
- break;
+ }
+ /*
+ * malloc "undo" storage buffer
+ */
+ memdup ((u_char **) & server_port_save,
+ (u_char *) & server_port, sizeof (server_port));
+
+ if (NULL == server_port_save /* if malloc, or whatever, failed: */ )
+ {
+ netsnmp_set_request_error (reqinfo, requests,
+ SNMP_ERR_RESOURCEUNAVAILABLE);
+ }
+ else
+ {
+ netsnmp_request_add_list_data (requests,
+ netsnmp_create_data_list
+ ("upgradeservport",
+ server_port_save, free));
+ }
+ break;
+
+ case MODE_SET_FREE:
+ /*
+ * free resources allocated in RESERVE1 and/or
+ * RESERVE2. Something failed somewhere, and the states
+ * below won't be called.
+ */
+ free (server_port_save);
+ break;
- default:
- /* we should never get here, so this is a really bad error */
- snmp_log(LOG_ERR, "unknown mode (%d) in handle_eocSoftwareUpgradeServerPort\n", reqinfo->mode );
- return SNMP_ERR_GENERR;
+ case MODE_SET_ACTION:
+ /*
+ * perform the value change here
+ */
+ value = *(requests->requestvb->val.integer);
+
+ sprintf (buffer, "%d", value);
+
+ ret = libspid_config_write_item (
+ LIBSPID_SYSTEM_CONF_PATH,
+ LIBSPID_SYSTEM_CONF_LABEL_UPGRADE_SERVER_PORT,
+ buffer);
+ if (LIBSPID_SUCCESS != ret)
+ {
+ snmp_log (LOG_ERR, "libspid_config_write_item error\n");
+ netsnmp_set_request_error (reqinfo, requests,
+ SNMP_ERR_COMMITFAILED);
+ }
+ break;
+
+ case MODE_SET_COMMIT:
+ /* delete temporary storage */
+ free (server_port_save);
+ break;
+
+ case MODE_SET_UNDO:
+ /* UNDO and return to previous value for the object */
+ value =
+ *((u_long *) netsnmp_request_get_list_data (requests,
+ "upgradeservport"));
+
+ sprintf (buffer, "%d", value);
+
+ ret = libspid_config_write_item (
+ LIBSPID_SYSTEM_CONF_PATH,
+ LIBSPID_SYSTEM_CONF_LABEL_UPGRADE_SERVER_PORT,
+ buffer);
+ if (LIBSPID_SUCCESS != ret)
+ {
+ snmp_log (LOG_ERR, "libspid_config_write_item error\n");
+ netsnmp_set_request_error (reqinfo, requests,
+ SNMP_ERR_UNDOFAILED);
+ }
+ free (server_port_save);
+ break;
+
+ default:
+ /* we should never get here, so this is a really bad error */
+ snmp_log (LOG_ERR, "unknown mode (%d) in "
+ "handle_eocSoftwareUpgradeServerPort\n", reqinfo->mode);
+ return SNMP_ERR_GENERR;
}
return SNMP_ERR_NOERROR;
@@ -206,153 +411,371 @@ handle_eocSoftwareUpgradeLogin(netsnmp_mib_handler *handler,
netsnmp_request_info *requests)
{
int ret;
- /* We are never called for a GETNEXT if it's registered as a
- "instance", as it's "magically" handled for us. */
-
- /* a instance handler also only hands us one request at a time, so
- we don't need to loop over a list of requests; we'll only get one. */
-
- switch(reqinfo->mode) {
- case MODE_GET:
- snmp_set_var_typed_value(requests->requestvb, ASN_OCTET_STR,
- (u_char *) /* XXX: a pointer to the scalar's data */,
- /* XXX: the length of the data in bytes */);
- break;
+ char login[SW_UPGRADE_LOGIN_MAX_LEN];
+ char *login_save = NULL;
+ u_char *value = NULL;
+
+ char buffer[LIBSPID_LINE_MAX_LEN];
+
+ /*
+ * We are never called for a GETNEXT if it's registered as a
+ * "instance", as it's "magically" handled for us.
+ */
+
+ /*
+ * a instance handler also only hands us one request at a time, so
+ * we don't need to loop over a list of requests; we'll only get one.
+ */
+
+ switch (reqinfo->mode)
+ {
+ case MODE_GET:
+ /* read buffer for software upgrade login from config file */
+ ret = libspid_config_read_item (
+ LIBSPID_SYSTEM_CONF_PATH,
+ LIBSPID_SYSTEM_CONF_LABEL_UPGRADE_SERVER_LOGIN,
+ buffer, LIBSPID_LINE_MAX_LEN);
+ if (LIBSPID_SUCCESS != ret)
+ {
+ snmp_log (LOG_ERR, "libspid_config_read_item error\n");
+ /* login set to empty string to permit walk requests */
+ strcpy (login, "");
+ }
+ else
+ {
+ /*
+ * if the buffer read from config file is larger than
+ * maximum value,
+ * copy only maximum permitted number of bytes
+ */
+ strncpy (login, buffer, SW_UPGRADE_LOGIN_MAX_LEN - 1);
+ login[SW_UPGRADE_LOGIN_MAX_LEN - 1] = '\0';
+ }
+ snmp_set_var_typed_value (requests->requestvb, ASN_OCTET_STR,
+ (u_char *) login, strlen (login));
+ break;
/*
* SET REQUEST
*
* multiple states in the transaction. See:
- * http://www.net-snmp.org/tutorial-5/toolkit/mib_module/set-actions.jpg
+ * http://www.net-snmp.org/tutorial-5/toolkit/mib_module/
+ * set-actions.jpg
*/
- case MODE_SET_RESERVE1:
- /* or you could use netsnmp_check_vb_type_and_size instead */
- ret = netsnmp_check_vb_type(requests->requestvb, ASN_OCTET_STR);
- if ( ret != SNMP_ERR_NOERROR ) {
- netsnmp_set_request_error(reqinfo, requests, ret );
- }
- break;
-
- case MODE_SET_RESERVE2:
- /* XXX malloc "undo" storage buffer */
- if (/* XXX if malloc, or whatever, failed: */) {
- netsnmp_set_request_error(reqinfo, requests, SNMP_ERR_RESOURCEUNAVAILABLE);
- }
- break;
-
- case MODE_SET_FREE:
- /* XXX: free resources allocated in RESERVE1 and/or
- RESERVE2. Something failed somewhere, and the states
- below won't be called. */
- break;
-
- case MODE_SET_ACTION:
- /* XXX: perform the value change here */
- if (/* XXX: error? */) {
- netsnmp_set_request_error(reqinfo, requests, /* some error */);
- }
- break;
-
- case MODE_SET_COMMIT:
- /* XXX: delete temporary storage */
- if (/* XXX: error? */) {
- /* try _really_really_ hard to never get to this point */
- netsnmp_set_request_error(reqinfo, requests, SNMP_ERR_COMMITFAILED);
- }
- break;
-
- case MODE_SET_UNDO:
- /* XXX: UNDO and return to previous value for the object */
- if (/* XXX: error? */) {
- /* try _really_really_ hard to never get to this point */
- netsnmp_set_request_error(reqinfo, requests, SNMP_ERR_UNDOFAILED);
- }
- break;
+ case MODE_SET_RESERVE1:
+ /* check type of set value */
+ ret = netsnmp_check_vb_type (requests->requestvb, ASN_OCTET_STR);
+ if (ret != SNMP_ERR_NOERROR)
+ {
+ netsnmp_set_request_error (reqinfo, requests, ret);
+ }
+
+ /* check size range of set value */
+ ret = netsnmp_check_vb_size_range (requests->requestvb,
+ SW_UPGRADE_LOGIN_MIN_LEN - 1,
+ SW_UPGRADE_LOGIN_MAX_LEN - 1);
+ if (ret != SNMP_ERR_NOERROR)
+ {
+ netsnmp_set_request_error (reqinfo, requests, ret);
+ }
+ break;
+
+ case MODE_SET_RESERVE2:
+ /*
+ * malloc "undo" storage buffer
+ */
+ /* read buffer for software upgrade login from config file */
+ ret = libspid_config_read_item (
+ LIBSPID_SYSTEM_CONF_PATH,
+ LIBSPID_SYSTEM_CONF_LABEL_UPGRADE_SERVER_LOGIN,
+ buffer, LIBSPID_LINE_MAX_LEN);
+ if (LIBSPID_SUCCESS != ret)
+ {
+ snmp_log (LOG_ERR, "libspid_config_read_item error\n");
+ netsnmp_set_request_error (reqinfo, requests,
+ SNMP_ERR_RESOURCEUNAVAILABLE);
+ }
+ else
+ {
+ /*
+ * if the buffer read from config file is larger than
+ * maximum value,
+ * copy only maximum permitted number of bytes
+ */
+ strncpy (login, buffer, SW_UPGRADE_LOGIN_MAX_LEN - 1);
+ login[SW_UPGRADE_LOGIN_MAX_LEN - 1] = '\0';
+ }
+ memdup ((u_char **) & login_save, (u_char *) login, sizeof (login));
+ if (NULL == login_save /* if malloc, or whatever, failed: */ )
+ {
+ netsnmp_set_request_error (reqinfo, requests,
+ SNMP_ERR_RESOURCEUNAVAILABLE);
+ }
+ else
+ {
+ netsnmp_request_add_list_data (requests,
+ netsnmp_create_data_list
+ ("upgradelogin", login_save,
+ free));
+ }
+ break;
+
+ case MODE_SET_FREE:
+ /*
+ * free resources allocated in RESERVE1 and/or
+ * RESERVE2. Something failed somewhere, and the states
+ * below won't be called.
+ */
+ free (login_save);
+ break;
- default:
- /* we should never get here, so this is a really bad error */
- snmp_log(LOG_ERR, "unknown mode (%d) in handle_eocSoftwareUpgradeLogin\n", reqinfo->mode );
- return SNMP_ERR_GENERR;
+ case MODE_SET_ACTION:
+ /*
+ * perform the value change here
+ */
+ value = requests->requestvb->val.string;
+
+ /* copy SET request variable buffer and add terminal 0 */
+ strncpy (login, value, requests->requestvb->val_len);
+ login[requests->requestvb->val_len] = '\0';
+
+ /* write null-terminated buffer to config file */
+ ret = libspid_config_write_item (
+ LIBSPID_SYSTEM_CONF_PATH,
+ LIBSPID_SYSTEM_CONF_LABEL_UPGRADE_SERVER_LOGIN,
+ login);
+
+ if (LIBSPID_SUCCESS != ret /* error? */ )
+ {
+ netsnmp_set_request_error (reqinfo, requests,
+ SNMP_ERR_COMMITFAILED);
+ }
+ break;
+
+ case MODE_SET_COMMIT:
+ /* delete temporary storage */
+ free (login_save);
+ break;
+
+ case MODE_SET_UNDO:
+ /*
+ * UNDO and return to previous value for the object
+ */
+ value =
+ (u_char *) netsnmp_request_get_list_data (requests,
+ "upgradelogin");
+ /* restore previous value in config file */
+ ret = libspid_config_write_item (
+ LIBSPID_SYSTEM_CONF_PATH,
+ LIBSPID_SYSTEM_CONF_LABEL_UPGRADE_SERVER_LOGIN,
+ value);
+
+ if (LIBSPID_SUCCESS != ret /* error? */ )
+ {
+ netsnmp_set_request_error (reqinfo, requests,
+ SNMP_ERR_UNDOFAILED);
+ }
+ break;
+
+ default:
+ /* we should never get here, so this is a really bad error */
+ snmp_log (LOG_ERR, "unknown mode (%d) in "
+ "handle_eocSoftwareUpgradeLogin\n", reqinfo->mode);
+ return SNMP_ERR_GENERR;
}
return SNMP_ERR_NOERROR;
}
+
int
-handle_eocSoftwareUpgradePassWord(netsnmp_mib_handler *handler,
- netsnmp_handler_registration *reginfo,
- netsnmp_agent_request_info *reqinfo,
- netsnmp_request_info *requests)
+handle_eocSoftwareUpgradePassWord (netsnmp_mib_handler * handler,
+ netsnmp_handler_registration * reginfo,
+ netsnmp_agent_request_info * reqinfo,
+ netsnmp_request_info * requests)
{
int ret;
- /* We are never called for a GETNEXT if it's registered as a
- "instance", as it's "magically" handled for us. */
- /* a instance handler also only hands us one request at a time, so
- we don't need to loop over a list of requests; we'll only get one. */
-
- switch(reqinfo->mode) {
-
- case MODE_GET:
- snmp_set_var_typed_value(requests->requestvb, ASN_OCTET_STR,
- (u_char *) /* XXX: a pointer to the scalar's data */,
- /* XXX: the length of the data in bytes */);
- break;
+ char password[SW_UPGRADE_PASSWORD_MAX_LEN];
+ char *password_save = NULL;
+ u_char *value = NULL;
+
+ char buffer[LIBSPID_LINE_MAX_LEN];
+
+ /*
+ * We are never called for a GETNEXT if it's registered as a
+ * "instance", as it's "magically" handled for us.
+ */
+
+ /*
+ * a instance handler also only hands us one request at a time, so
+ * we don't need to loop over a list of requests; we'll only get one.
+ */
+
+ switch (reqinfo->mode)
+ {
+ case MODE_GET:
+ /* read buffer for software upgrade password from config file */
+ ret = libspid_config_read_item (
+ LIBSPID_SYSTEM_CONF_PATH,
+ LIBSPID_SYSTEM_CONF_LABEL_UPGRADE_SERVER_PASSWORD,
+ buffer, LIBSPID_LINE_MAX_LEN);
+ if (LIBSPID_SUCCESS != ret)
+ {
+ snmp_log (LOG_ERR, "libspid_config_read_item error\n");
+ /* password set to empty string to permit walk requests */
+ strcpy (password, "");
+ }
+ else
+ {
+ /*
+ * if the buffer read from config file is larger than
+ * maximum value,
+ * copy only maximum permitted number of bytes
+ */
+ strncpy (password, buffer, SW_UPGRADE_PASSWORD_MAX_LEN - 1);
+ password[SW_UPGRADE_PASSWORD_MAX_LEN - 1] = '\0';
+ }
+
+ snmp_set_var_typed_value (requests->requestvb, ASN_OCTET_STR,
+ (u_char *) password, strlen (password));
+ break;
/*
* SET REQUEST
*
* multiple states in the transaction. See:
- * http://www.net-snmp.org/tutorial-5/toolkit/mib_module/set-actions.jpg
+ * http://www.net-snmp.org/tutorial-5/toolkit/mib_module/
+ * set-actions.jpg
*/
- case MODE_SET_RESERVE1:
- /* or you could use netsnmp_check_vb_type_and_size instead */
- ret = netsnmp_check_vb_type(requests->requestvb, ASN_OCTET_STR);
- if ( ret != SNMP_ERR_NOERROR ) {
- netsnmp_set_request_error(reqinfo, requests, ret );
- }
- break;
+ case MODE_SET_RESERVE1:
+ /* check type of set value */
+ ret = netsnmp_check_vb_type (requests->requestvb, ASN_OCTET_STR);
+ if (ret != SNMP_ERR_NOERROR)
+ {
+ netsnmp_set_request_error (reqinfo, requests, ret);
+ }
+
+ /* check size range of set value */
+ ret = netsnmp_check_vb_size_range (requests->requestvb,
+ SW_UPGRADE_PASSWORD_MIN_LEN - 1,
+ SW_UPGRADE_PASSWORD_MAX_LEN - 1);
+ if (ret != SNMP_ERR_NOERROR)
+ {
+ netsnmp_set_request_error (reqinfo, requests, ret);
+ }
+ break;
+
+ case MODE_SET_RESERVE2:
+ /*
+ * malloc "undo" storage buffer
+ */
+ /* read buffer for software upgrade password from config file */
+ ret = libspid_config_read_item (
+ LIBSPID_SYSTEM_CONF_PATH,
+ LIBSPID_SYSTEM_CONF_LABEL_UPGRADE_SERVER_PASSWORD,
+ buffer, LIBSPID_LINE_MAX_LEN);
+ if (LIBSPID_SUCCESS != ret)
+ {
+ snmp_log (LOG_ERR, "libspid_config_read_item error\n");
+ netsnmp_set_request_error (reqinfo, requests,
+ SNMP_ERR_RESOURCEUNAVAILABLE);
+ }
+ else
+ {
+ /*
+ * if the buffer read from config file is larger than
+ * maximum value,
+ * copy only maximum permitted number of bytes
+ */
+ strncpy (password, buffer, SW_UPGRADE_PASSWORD_MAX_LEN - 1);
+ password[SW_UPGRADE_PASSWORD_MAX_LEN - 1] = '\0';
+ }
+
+ memdup ((u_char **) & password_save,
+ (u_char *) password, sizeof (password));
+ if (NULL == password_save /* if malloc, or whatever, failed: */ )
+ {
+ netsnmp_set_request_error (reqinfo, requests,
+ SNMP_ERR_RESOURCEUNAVAILABLE);
+ }
+ else
+ {
+ netsnmp_request_add_list_data (requests,
+ netsnmp_create_data_list
+ ("upgradepasswd", password_save,
+ free));
+ }
+ break;
+
+ case MODE_SET_FREE:
+ /*
+ * free resources allocated in RESERVE1 and/or
+ * RESERVE2. Something failed somewhere, and the states
+ * below won't be called.
+ */
+ free (password_save);
+ break;
- case MODE_SET_RESERVE2:
- /* XXX malloc "undo" storage buffer */
- if (/* XXX if malloc, or whatever, failed: */) {
- netsnmp_set_request_error(reqinfo, requests, SNMP_ERR_RESOURCEUNAVAILABLE);
- }
- break;
-
- case MODE_SET_FREE:
- /* XXX: free resources allocated in RESERVE1 and/or
- RESERVE2. Something failed somewhere, and the states
- below won't be called. */
- break;
-
- case MODE_SET_ACTION:
- /* XXX: perform the value change here */
- if (/* XXX: error? */) {
- netsnmp_set_request_error(reqinfo, requests, /* some error */);
- }
- break;
+ case MODE_SET_ACTION:
+ /*
+ * perform the value change here
+ */
+ value = requests->requestvb->val.string;
- case MODE_SET_COMMIT:
- /* XXX: delete temporary storage */
- if (/* XXX: error? */) {
- /* try _really_really_ hard to never get to this point */
- netsnmp_set_request_error(reqinfo, requests, SNMP_ERR_COMMITFAILED);
- }
- break;
+ /* copy SET request variable buffer and add terminal 0 */
+ strncpy (password, value, requests->requestvb->val_len);
+ password[requests->requestvb->val_len] = '\0';
- case MODE_SET_UNDO:
- /* XXX: UNDO and return to previous value for the object */
- if (/* XXX: error? */) {
- /* try _really_really_ hard to never get to this point */
- netsnmp_set_request_error(reqinfo, requests, SNMP_ERR_UNDOFAILED);
- }
- break;
- default:
- /* we should never get here, so this is a really bad error */
- snmp_log(LOG_ERR, "unknown mode (%d) in handle_eocSoftwareUpgradePassWord\n", reqinfo->mode );
- return SNMP_ERR_GENERR;
+ /* write null-terminated buffer to config file */
+ ret = libspid_config_write_item (
+ LIBSPID_SYSTEM_CONF_PATH,
+ LIBSPID_SYSTEM_CONF_LABEL_UPGRADE_SERVER_PASSWORD,
+ password);
+
+ if (LIBSPID_SUCCESS != ret /* error? */ )
+ {
+ netsnmp_set_request_error (reqinfo, requests,
+ SNMP_ERR_COMMITFAILED);
+ }
+ break;
+
+ case MODE_SET_COMMIT:
+ /*
+ * delete temporary storage
+ */
+ free (password_save);
+ break;
+
+ case MODE_SET_UNDO:
+ /*
+ * UNDO and return to previous value for the object
+ */
+ value =
+ (u_char *) netsnmp_request_get_list_data (requests,
+ "upgradepasswd");
+
+ /* restore previous value in config file */
+ ret = libspid_config_write_item (
+ LIBSPID_SYSTEM_CONF_PATH,
+ LIBSPID_SYSTEM_CONF_LABEL_UPGRADE_SERVER_PASSWORD,
+ value);
+
+ if (LIBSPID_SUCCESS != ret /* error? */ )
+ {
+ netsnmp_set_request_error (reqinfo, requests,
+ SNMP_ERR_UNDOFAILED);
+ }
+
+ free (password_save);
+ break;
+
+ default:
+ /* we should never get here, so this is a really bad error */
+ snmp_log (LOG_ERR, "unknown mode (%d) in "
+ "handle_eocSoftwareUpgradePassWord\n", reqinfo->mode);
+ return SNMP_ERR_GENERR;
}
return SNMP_ERR_NOERROR;
diff --git a/cleopatre/application/spidnetsnmp/agent/mibgroup/mstar-eoc-mib/eocSoftwareUpgradeGroup/eocSoftwareUpgradeGroup.h b/cleopatre/application/spidnetsnmp/agent/mibgroup/mstar-eoc-mib/eocSoftwareUpgradeGroup/eocSoftwareUpgradeGroup.h
index 295bd478d8..0edc69f745 100644
--- a/cleopatre/application/spidnetsnmp/agent/mibgroup/mstar-eoc-mib/eocSoftwareUpgradeGroup/eocSoftwareUpgradeGroup.h
+++ b/cleopatre/application/spidnetsnmp/agent/mibgroup/mstar-eoc-mib/eocSoftwareUpgradeGroup/eocSoftwareUpgradeGroup.h
@@ -5,9 +5,13 @@
#ifndef EOCSOFTWAREUPGRADEGROUP_H
#define EOCSOFTWAREUPGRADEGROUP_H
+/* include common header */
+#include "EoCCommon.h"
+
+
/* function declarations */
void init_eocSoftwareUpgradeGroup(void);
-Netsnmp_Node_Handler handle_eocSoftwaretUpgradeServerIP;
+Netsnmp_Node_Handler handle_eocSoftwareUpgradeServerIP;
Netsnmp_Node_Handler handle_eocSoftwareUpgradeServerPort;
Netsnmp_Node_Handler handle_eocSoftwareUpgradeLogin;
Netsnmp_Node_Handler handle_eocSoftwareUpgradePassWord;
diff --git a/cleopatre/application/spidnetsnmp/agent/mibgroup/mstar-eoc-mib/eocSoftwareUpgradeGroup/eocSoftwareUpgradeTable.h b/cleopatre/application/spidnetsnmp/agent/mibgroup/mstar-eoc-mib/eocSoftwareUpgradeGroup/eocSoftwareUpgradeTable.h
index 3ad391701f..c535b88c35 100644
--- a/cleopatre/application/spidnetsnmp/agent/mibgroup/mstar-eoc-mib/eocSoftwareUpgradeGroup/eocSoftwareUpgradeTable.h
+++ b/cleopatre/application/spidnetsnmp/agent/mibgroup/mstar-eoc-mib/eocSoftwareUpgradeGroup/eocSoftwareUpgradeTable.h
@@ -1,5 +1,5 @@
-//config_require(mstar-eoc-mib/eocSoftwareUpgradeGroup/eocSoftwareUpgradeTable/eocSoftwareUpgradeTable)
-//config_require(mstar-eoc-mib/eocSoftwareUpgradeGroup/eocSoftwareUpgradeTable/eocSoftwareUpgradeTable_data_get)
-//config_require(mstar-eoc-mib/eocSoftwareUpgradeGroup/eocSoftwareUpgradeTable/eocSoftwareUpgradeTable_data_access)
-//config_require(mstar-eoc-mib/eocSoftwareUpgradeGroup/eocSoftwareUpgradeTable/eocSoftwareUpgradeTable_interface)
-//config_require(mstar-eoc-mib/eocSoftwareUpgradeGroup/eocSoftwareUpgradeTable/eocSoftwareUpgradeTable_data_set)
+config_require(mstar-eoc-mib/eocSoftwareUpgradeGroup/eocSoftwareUpgradeTable/eocSoftwareUpgradeTable)
+config_require(mstar-eoc-mib/eocSoftwareUpgradeGroup/eocSoftwareUpgradeTable/eocSoftwareUpgradeTable_data_get)
+config_require(mstar-eoc-mib/eocSoftwareUpgradeGroup/eocSoftwareUpgradeTable/eocSoftwareUpgradeTable_data_access)
+config_require(mstar-eoc-mib/eocSoftwareUpgradeGroup/eocSoftwareUpgradeTable/eocSoftwareUpgradeTable_interface)
+config_require(mstar-eoc-mib/eocSoftwareUpgradeGroup/eocSoftwareUpgradeTable/eocSoftwareUpgradeTable_data_set)
diff --git a/cleopatre/application/spidnetsnmp/agent/mibgroup/mstar-eoc-mib/eocSoftwareUpgradeGroup/eocSoftwareUpgradeTable/eocSoftwareUpgradeTable.h b/cleopatre/application/spidnetsnmp/agent/mibgroup/mstar-eoc-mib/eocSoftwareUpgradeGroup/eocSoftwareUpgradeTable/eocSoftwareUpgradeTable.h
index e28c1ae605..8438a16612 100644
--- a/cleopatre/application/spidnetsnmp/agent/mibgroup/mstar-eoc-mib/eocSoftwareUpgradeGroup/eocSoftwareUpgradeTable/eocSoftwareUpgradeTable.h
+++ b/cleopatre/application/spidnetsnmp/agent/mibgroup/mstar-eoc-mib/eocSoftwareUpgradeGroup/eocSoftwareUpgradeTable/eocSoftwareUpgradeTable.h
@@ -18,18 +18,15 @@ extern "C" {
*/
#include <net-snmp/library/asn1.h>
-/* other required module components */
- /* *INDENT-OFF* */
-config_add_mib(NSCRTV-EPONEOC-MOD-EOC-MIB)
-config_require(NSCRTV-EPONEOC-MOD-EOC-MIB/eocSoftwareUpgradeTable/eocSoftwareUpgradeTable_interface)
-config_require(NSCRTV-EPONEOC-MOD-EOC-MIB/eocSoftwareUpgradeTable/eocSoftwareUpgradeTable_data_access)
-config_require(NSCRTV-EPONEOC-MOD-EOC-MIB/eocSoftwareUpgradeTable/eocSoftwareUpgradeTable_data_get)
-config_require(NSCRTV-EPONEOC-MOD-EOC-MIB/eocSoftwareUpgradeTable/eocSoftwareUpgradeTable_data_set)
- /* *INDENT-ON* */
+
+ /* *INDENT-ON* */
/* OID and column number definitions for eocSoftwareUpgradeTable */
#include "eocSoftwareUpgradeTable_oids.h"
+/* include common header */
+#include "EoCCommon.h"
+
/* enum definions */
#include "eocSoftwareUpgradeTable_enums.h"
@@ -76,34 +73,34 @@ typedef netsnmp_data_list eocSoftwareUpgradeTable_registration;
* eocSoftwareUpgradeTable.
*/
typedef struct eocSoftwareUpgradeTable_data_s {
-
+
/*
* eocSoftwareUpgradeMACAddress(3)/MacAddress/ASN_OCTET_STR/char(char)//L/A/W/e/R/d/H
*/
char eocSoftwareUpgradeMACAddress[6];
size_t eocSoftwareUpgradeMACAddress_len; /* # of char elements, not bytes */
-
+
/*
* eocSoftwareUpgradeDevType(4)/INTEGER/ASN_INTEGER/long(u_long)//l/A/W/E/r/d/h
*/
u_long eocSoftwareUpgradeDevType;
-
+
/*
* eocSoftwareUpgradeFileName(5)/OCTETSTR/ASN_OCTET_STR/char(char)//L/A/W/e/R/d/h
*/
char eocSoftwareUpgradeFileName[255];
size_t eocSoftwareUpgradeFileName_len; /* # of char elements, not bytes */
-
+
/*
* eocSoftwareUpgradeProceed(6)/INTEGER/ASN_INTEGER/long(u_long)//l/A/W/E/r/d/h
*/
u_long eocSoftwareUpgradeProceed;
-
+
/*
* eocSoftwareUpgradeResult(7)/INTEGER/ASN_INTEGER/long(u_long)//l/A/w/E/r/D/h
*/
u_long eocSoftwareUpgradeResult;
-
+
} eocSoftwareUpgradeTable_data;
@@ -152,9 +149,9 @@ typedef struct eocSoftwareUpgradeTable_rowreq_ctx_s {
/** this must be first for container compare to work */
netsnmp_index oid_idx;
oid oid_tmp[MAX_eocSoftwareUpgradeTable_IDX_LEN];
-
+
eocSoftwareUpgradeTable_mib_index tbl_idx;
-
+
eocSoftwareUpgradeTable_data data;
eocSoftwareUpgradeTable_undo_data * undo;
unsigned int column_set_flags; /* flags for set columns */
@@ -169,7 +166,7 @@ typedef struct eocSoftwareUpgradeTable_rowreq_ctx_s {
/*
* TODO:131:o: | |-> Add useful data to eocSoftwareUpgradeTable rowreq context.
*/
-
+
/*
* storage for future expansion
*/
@@ -200,6 +197,8 @@ typedef struct eocSoftwareUpgradeTable_ref_rowreq_ctx_s {
extern oid eocSoftwareUpgradeTable_oid[];
extern int eocSoftwareUpgradeTable_oid_size;
+extern u_long eocSoftwareUpgradeResult[LIBSPID_WHITE_LIST_MAX_STA_NUM+1];
+extern int table_released;
#include "eocSoftwareUpgradeTable_interface.h"
#include "eocSoftwareUpgradeTable_data_access.h"
diff --git a/cleopatre/application/spidnetsnmp/agent/mibgroup/mstar-eoc-mib/eocSoftwareUpgradeGroup/eocSoftwareUpgradeTable/eocSoftwareUpgradeTable_data_access.c b/cleopatre/application/spidnetsnmp/agent/mibgroup/mstar-eoc-mib/eocSoftwareUpgradeGroup/eocSoftwareUpgradeTable/eocSoftwareUpgradeTable_data_access.c
index bae508d707..9afb401997 100644
--- a/cleopatre/application/spidnetsnmp/agent/mibgroup/mstar-eoc-mib/eocSoftwareUpgradeGroup/eocSoftwareUpgradeTable/eocSoftwareUpgradeTable_data_access.c
+++ b/cleopatre/application/spidnetsnmp/agent/mibgroup/mstar-eoc-mib/eocSoftwareUpgradeGroup/eocSoftwareUpgradeTable/eocSoftwareUpgradeTable_data_access.c
@@ -1,6 +1,6 @@
/*
* Note: this file originally auto-generated by mib2c using
- * version : 14170 $ of $
+ * version : 14170 $ of $
*
* $Id:$
*/
@@ -15,12 +15,19 @@
#include "eocSoftwareUpgradeTable_data_access.h"
+#include <ctype.h> /* for tolower() */
+
+/* array of upgrade results for each station */
+u_long eocSoftwareUpgradeResult[LIBSPID_WHITE_LIST_MAX_STA_NUM + 1];
+/* indication of table release */
+int table_released;
+
/** @ingroup interface
* @addtogroup data_access data_access: Routines to access data
*
* These routines are used to locate the data used to satisfy
* requests.
- *
+ *
* @{
*/
/**********************************************************************
@@ -57,6 +64,9 @@ eocSoftwareUpgradeTable_init_data(eocSoftwareUpgradeTable_registration * eocSoft
* TODO:303:o: Initialize eocSoftwareUpgradeTable data.
*/
+ /* initialize array of upgrade results */
+ memset (eocSoftwareUpgradeResult, 0, LIBSPID_WHITE_LIST_MAX_STA_NUM + 1);
+
return MFD_SUCCESS;
} /* eocSoftwareUpgradeTable_init_data */
@@ -96,7 +106,7 @@ eocSoftwareUpgradeTable_container_init(netsnmp_container **container_ptr_ptr,
netsnmp_cache *cache)
{
DEBUGMSGTL(("verbose:eocSoftwareUpgradeTable:eocSoftwareUpgradeTable_container_init","called\n"));
-
+
if (NULL == container_ptr_ptr) {
snmp_log(LOG_ERR,"bad container param to eocSoftwareUpgradeTable_container_init\n");
return;
@@ -122,6 +132,9 @@ eocSoftwareUpgradeTable_container_init(netsnmp_container **container_ptr_ptr,
* cache->enabled to 0.
*/
cache->timeout = EOCSOFTWAREUPGRADETABLE_CACHE_TIMEOUT; /* seconds */
+
+ /* initialize table release indication */
+ table_released = 0;
} /* eocSoftwareUpgradeTable_container_init */
/**
@@ -144,7 +157,7 @@ void
eocSoftwareUpgradeTable_container_shutdown(netsnmp_container *container_ptr)
{
DEBUGMSGTL(("verbose:eocSoftwareUpgradeTable:eocSoftwareUpgradeTable_container_shutdown","called\n"));
-
+
if (NULL == container_ptr) {
snmp_log(LOG_ERR,"bad params to eocSoftwareUpgradeTable_container_shutdown\n");
return;
@@ -189,53 +202,337 @@ int
eocSoftwareUpgradeTable_container_load(netsnmp_container *container)
{
eocSoftwareUpgradeTable_rowreq_ctx *rowreq_ctx;
- size_t count = 0;
+ size_t count = 0;
/*
* temporary storage for index values
*/
- /*
- * eocSoftwareUpgradeCBATCardIndex(1)/INTEGER/ASN_INTEGER/long(long)//l/A/w/e/R/d/h
- */
- long eocSoftwareUpgradeCBATCardIndex;
- /*
- * eocSoftwareUpgradeCNUIndex(2)/INTEGER/ASN_INTEGER/long(long)//l/A/w/e/R/d/h
- */
- long eocSoftwareUpgradeCNUIndex;
+ /*
+ * eocSoftwareUpgradeCBATCardIndex(1)/INTEGER/
+ *ASN_INTEGER/long(long)//l/A/w/e/R/d/h
+ */
+ long eocSoftwareUpgradeCBATCardIndex = 0;
+ /*
+ * eocSoftwareUpgradeCNUIndex(2)/INTEGER/ASN_INTEGER/
+ *long(long)//l/A/w/e/R/d/h
+ */
+ long eocSoftwareUpgradeCNUIndex;
+
+ char eocSoftwareUpgradeMACAddress[6];
+ size_t eocSoftwareUpgradeMACAddress_len = 6;
+ u_long eocSoftwareUpgradeDevType;
+ char eocSoftwareUpgradeFileName[DEFAULT_SNMP_STRING_MAX_LENGTH];
+ size_t eocSoftwareUpgradeFileName_len = 0;
+ u_long eocSoftwareUpgradeProceed = 0;
- DEBUGMSGTL(("verbose:eocSoftwareUpgradeTable:eocSoftwareUpgradeTable_container_load","called\n"));
+
+ /* declarations for calls to libspid */
+ char filename_buffer[LIBSPID_LINE_MAX_LEN];
+ char slave_default[LIBSPID_LINE_MAX_LEN];
+ const char delimiters[2] = LIBSPID_UPDATE_INFO_DELIMITER "\0";
+ unsigned int elt_number = LIBSPID_ELT_MAX_NB;
+ char buffer[LIBSPID_LINE_MAX_LEN];
+ char *elt_buffer[LIBSPID_ELT_MAX_NB];
+
+ /* white list entries read from config file */
+ libspid_eoc_wl_entry_t wl_config_entries[LIBSPID_WHITE_LIST_MAX_STA_NUM];
+ spc300_nvram_t nvram;
+
+ char mac_str[LIBSPID_MAC_STR_LEN];
+
+ int mac_address_count;
+ int i, index;
+ int tmp;
+ int update_action;
+ int update_last_action;
+ int update_result;
+ int tei;
+
+ DEBUGMSGTL (("verbose:eocSoftwareUpgradeTable:",
+ "eocSoftwareUpgradeTable_container_load", "called\n"));
+
+ /* reset indication of table release */
+ table_released = 0;
/*
- * TODO:351:M: |-> Load/update data in the eocSoftwareUpgradeTable container.
+ * TODO:351:M: |-> Load/update data in the eocSoftwareUpgradeTable
+ * container.
* loop over your eocSoftwareUpgradeTable data, allocate a rowreq context,
* set the index(es) [and data, optionally] and insert into
* the container.
*/
- while( 1 ) {
- /*
- * check for end of data; bail out if there is no more data
- */
- if( 1 )
- break;
+ memset (wl_config_entries, 0x0, sizeof (wl_config_entries));
+
+
+ /* check errors in contents of white list prior to reading */
+ if (LIBSPID_SUCCESS != libspid_eoc_wl_check ())
+ {
+ snmp_log (LOG_ERR,
+ "errors detected in whitelist configuration file\n");
+ return MFD_ERROR;
+ }
+
+ /* get current contents of white list config file */
+ if (LIBSPID_SUCCESS != libspid_eoc_wl_get_list (wl_config_entries,
+ &mac_address_count))
+ {
+ snmp_log (LOG_ERR, "White list config file not read correctly\n");
+ return MFD_ERROR;
+ }
+
+ /* read default filename for slaves
+ (used in case no custom filename is set) */
+ if (LIBSPID_SUCCESS !=
+ libspid_config_read_item (
+ LIBSPID_SYSTEM_CONF_PATH,
+ LIBSPID_SYSTEM_CONF_LABEL_UPGRADE_SLAVE_FILENAME,
+ slave_default, LIBSPID_LINE_MAX_LEN))
+ {
+ snmp_log (LOG_ERR, "libspid_config_read_item error in "
+ "reading default slave filename\n");
+ return MFD_RESOURCE_UNAVAILABLE;
+ }
+
+ for (i = 0; i <= mac_address_count; i++)
+ {
+ if (0 == i)
+ {
+ /* add master as first row of the table */
+
+ /* read NVRAM contents */
+ /* obtain master MAC address */
+ if (LIBSPID_SUCCESS !=
+ libspid_network_get_mac (LIBSPID_EOC_BR_IFACE, mac_str))
+ {
+ snmp_log (LOG_ERR, "libspid_network_get_mac error\n");
+ return MFD_RESOURCE_UNAVAILABLE;
+ }
+ else
+ {
+ /* convert master MAC address from string to char array */
+ if (LIBSPID_SUCCESS != libspid_mac_str_to_bin (
+ mac_str,
+ eocSoftwareUpgradeMACAddress))
+ {
+ snmp_log (LOG_ERR, "libspid_mac_str_to_bin error\n");
+ return MFD_RESOURCE_UNAVAILABLE;
+ }
+ }
+
+ /* set index in table to 0 for master */
+ eocSoftwareUpgradeCNUIndex = 0;
+
+
+ /* set device type to CLT for master */
+ eocSoftwareUpgradeDevType =
+ INTERNAL_EOCSOFTWAREUPGRADETABLE_EOCSOFTWAREUPGRADEDEVTYPE_CBAT;
+
+ /* read filename for master */
+ if (LIBSPID_SUCCESS !=
+ libspid_config_read_item (
+ LIBSPID_SYSTEM_CONF_PATH,
+ LIBSPID_SYSTEM_CONF_LABEL_UPGRADE_MASTER_FILENAME,
+ filename_buffer,
+ LIBSPID_LINE_MAX_LEN))
+ {
+ snmp_log (LOG_ERR, "libspid_config_read_item error in",
+ " reading master filename\n");
+ return MFD_RESOURCE_UNAVAILABLE;
+ }
+
+ /* set Proceed value if master upgrade is in progress */
+ if (eocSoftwareUpgradeResult[eocSoftwareUpgradeCNUIndex] ==
+ INTERNAL_EOCSOFTWAREUPGRADETABLE_EOCSOFTWAREUPGRADERESULT_UPGRADING)
+ {
+ eocSoftwareUpgradeProceed =
+ INTERNAL_EOCSOFTWAREUPGRADETABLE_EOCSOFTWAREUPGRADEPROCEED_UPGRADE;
+ }
+
+ }
+ else
+ {
+ /* consider only slaves that are allowed */
+ if (!strcmp (wl_config_entries[i - 1].auth, "1"))
+ {
+ strcpy (mac_str, wl_config_entries[i - 1].mac_addr);
+ /* make sure that mac address will be in lower case */
+ for (index = 0; index < LIBSPID_MAC_STR_LEN; index++)
+ {
+ mac_str[index] = tolower (mac_str[index]);
+ }
+ /* convert slave MAC address from string to char array */
+ if (LIBSPID_SUCCESS != libspid_mac_str_to_bin (
+ mac_str,
+ eocSoftwareUpgradeMACAddress))
+ {
+ snmp_log (LOG_ERR, "libspid_mac_str_to_bin error\n");
+ return MFD_RESOURCE_UNAVAILABLE;
+ }
+
+
+ /* set slave index from TEI in white list */
+ tmp = sscanf (wl_config_entries[i - 1].tei, "%ld", &tei);
+ if (1 != tmp)
+ {
+ snmp_log (LOG_ERR, "error setting software upgrade ",
+ "table index\n");
+ return MFD_RESOURCE_UNAVAILABLE;
+ }
+ eocSoftwareUpgradeCNUIndex = tei - 2;
+
+ /* check if slave MAC address exists in upgrade.info */
+ /*
+ * if MAC exists, read filename, action and result from
+ * upgrade.info,
+ * else copy default filename from system.conf and set action and
+ * result to none
+ */
+ /* initialize maximal number of elements for current slave */
+ elt_number = LIBSPID_ELT_MAX_NB;
+ if (LIBSPID_SUCCESS ==
+ libspid_config_read_line (LIBSPID_UPDATE_INFO_PATH,
+ delimiters, mac_str,
+ &elt_number, elt_buffer, buffer,
+ LIBSPID_LINE_MAX_LEN))
+ {
+
+ strcpy (filename_buffer, elt_buffer[0]);
+
+ /* read values of action and result fields */
+ if (1 != sscanf (elt_buffer[1], "%d", &update_action))
+ {
+ update_action = LIBSPID_UPDATE_ACTION_NONE;
+ }
+ if (1 != sscanf (elt_buffer[2], "%d", &update_result))
+ {
+ update_result = LIBSPID_UPDATE_NONE;
+ }
+ if (1 != sscanf (elt_buffer[3], "%d",
+ &update_last_action))
+ {
+ update_last_action = LIBSPID_UPDATE_ACTION_NONE;
+ }
+
+ if (LIBSPID_UPDATE_ACTION_UPLOAD == update_action)
+ {
+ eocSoftwareUpgradeProceed =
+ INTERNAL_EOCSOFTWAREUPGRADETABLE_EOCSOFTWAREUPGRADEPROCEED_UPLOAD;
+ }
+ else if (LIBSPID_UPDATE_ACTION_UPDATE == update_action
+ || LIBSPID_UPDATE_ACTION_TFTP_UPDATE ==
+ update_action)
+ {
+ /* regular update and TFTP update are both
+ * considered as update in agent */
+ eocSoftwareUpgradeProceed =
+ INTERNAL_EOCSOFTWAREUPGRADETABLE_EOCSOFTWAREUPGRADEPROCEED_UPGRADE;
+ }
+ else
+ {
+ eocSoftwareUpgradeProceed = 0;
+ }
+
+ if (update_last_action == LIBSPID_UPDATE_ACTION_UPLOAD)
+ {
+ switch (update_result)
+ {
+ case LIBSPID_UPDATE_RUNNING:
+ eocSoftwareUpgradeResult
+ [eocSoftwareUpgradeCNUIndex] =
+ INTERNAL_EOCSOFTWAREUPGRADETABLE_EOCSOFTWAREUPGRADERESULT_UPLOADING;
+ break;
+ case LIBSPID_UPDATE_SUCCESS:
+ eocSoftwareUpgradeResult
+ [eocSoftwareUpgradeCNUIndex] =
+ INTERNAL_EOCSOFTWAREUPGRADETABLE_EOCSOFTWAREUPGRADERESULT_UPLOADSUCCESS;
+ break;
+ case LIBSPID_UPDATE_FAILED:
+ eocSoftwareUpgradeResult
+ [eocSoftwareUpgradeCNUIndex] =
+ INTERNAL_EOCSOFTWAREUPGRADETABLE_EOCSOFTWAREUPGRADERESULT_UPLOADFAILED;
+ break;
+ default:
+ eocSoftwareUpgradeResult
+ [eocSoftwareUpgradeCNUIndex] =
+ INTERNAL_EOCSOFTWAREUPGRADETABLE_EOCSOFTWAREUPGRADERESULT_NONE;
+ break;
+ }
+ }
+ else if ((update_last_action ==
+ LIBSPID_UPDATE_ACTION_UPDATE) ||
+ (update_last_action ==
+ LIBSPID_UPDATE_ACTION_TFTP_UPDATE))
+ {
+ switch (update_result)
+ {
+ case LIBSPID_UPDATE_RUNNING:
+ eocSoftwareUpgradeResult
+ [eocSoftwareUpgradeCNUIndex] =
+ INTERNAL_EOCSOFTWAREUPGRADETABLE_EOCSOFTWAREUPGRADERESULT_UPGRADING;
+ break;
+ case LIBSPID_UPDATE_SUCCESS:
+ eocSoftwareUpgradeResult
+ [eocSoftwareUpgradeCNUIndex] =
+ INTERNAL_EOCSOFTWAREUPGRADETABLE_EOCSOFTWAREUPGRADERESULT_UPGRADESUCCESS;
+ break;
+ case LIBSPID_UPDATE_FAILED:
+ eocSoftwareUpgradeResult
+ [eocSoftwareUpgradeCNUIndex] =
+ INTERNAL_EOCSOFTWAREUPGRADETABLE_EOCSOFTWAREUPGRADERESULT_UPGRADEFAILED;
+ break;
+ default:
+ eocSoftwareUpgradeResult
+ [eocSoftwareUpgradeCNUIndex] =
+ INTERNAL_EOCSOFTWAREUPGRADETABLE_EOCSOFTWAREUPGRADERESULT_NONE;
+ break;
+ }
+
+ }
+ else
+ {
+ eocSoftwareUpgradeResult[eocSoftwareUpgradeCNUIndex] =
+ INTERNAL_EOCSOFTWAREUPGRADETABLE_EOCSOFTWAREUPGRADERESULT_NONE;
+ }
+ }
+ else
+ {
+ /* set buffer for filename to default slave filename */
+ strcpy (filename_buffer, slave_default);
+ eocSoftwareUpgradeProceed = 0;
+ eocSoftwareUpgradeResult[eocSoftwareUpgradeCNUIndex] =
+ INTERNAL_EOCSOFTWAREUPGRADETABLE_EOCSOFTWAREUPGRADERESULT_NONE;
+ }
+
+ /* set device type to CNU for slaves */
+ eocSoftwareUpgradeDevType =
+ INTERNAL_EOCSOFTWAREUPGRADETABLE_EOCSOFTWAREUPGRADEDEVTYPE_CNU;
+ }
+ else
+ continue;
+ }
/*
- * TODO:352:M: | |-> set indexes in new eocSoftwareUpgradeTable rowreq context.
+ * TODO:352:M: | |-> set indexes in new eocSoftwareUpgradeTable
+ * rowreq context.
* data context will be set from the param (unless NULL,
* in which case a new data context will be allocated)
*/
- rowreq_ctx = eocSoftwareUpgradeTable_allocate_rowreq_ctx(NULL);
- if (NULL == rowreq_ctx) {
- snmp_log(LOG_ERR, "memory allocation failed\n");
+ rowreq_ctx = eocSoftwareUpgradeTable_allocate_rowreq_ctx (NULL);
+ if (NULL == rowreq_ctx)
+ {
+ snmp_log (LOG_ERR, "memory allocation failed\n");
return MFD_RESOURCE_UNAVAILABLE;
}
- if(MFD_SUCCESS != eocSoftwareUpgradeTable_indexes_set(rowreq_ctx
- , eocSoftwareUpgradeCBATCardIndex
- , eocSoftwareUpgradeCNUIndex
- )) {
- snmp_log(LOG_ERR,"error setting index while loading "
- "eocSoftwareUpgradeTable data.\n");
- eocSoftwareUpgradeTable_release_rowreq_ctx(rowreq_ctx);
+ if (MFD_SUCCESS !=
+ eocSoftwareUpgradeTable_indexes_set (
+ rowreq_ctx,
+ eocSoftwareUpgradeCBATCardIndex,
+ eocSoftwareUpgradeCNUIndex))
+ {
+ snmp_log (LOG_ERR, "error setting index while loading "
+ "eocSoftwareUpgradeTable data.\n");
+ eocSoftwareUpgradeTable_release_rowreq_ctx (rowreq_ctx);
continue;
}
@@ -243,108 +540,126 @@ eocSoftwareUpgradeTable_container_load(netsnmp_container *container)
* TODO:352:r: | |-> populate eocSoftwareUpgradeTable data context.
* Populate data context here. (optionally, delay until row prep)
*/
- /*
- * TRANSIENT or semi-TRANSIENT data:
- * copy data or save any info needed to do it in row_prep.
- */
- /*
- * setup/save data for eocSoftwareUpgradeMACAddress
- * eocSoftwareUpgradeMACAddress(3)/MacAddress/ASN_OCTET_STR/char(char)//L/A/W/e/R/d/H
- */
- /*
- * TODO:246:r: |-> Define eocSoftwareUpgradeMACAddress mapping.
- * Map values between raw/native values and MIB values
- *
- * if(MFD_SUCCESS !=
- * eocSoftwareUpgradeMACAddress_map(&rowreq_ctx->data.eocSoftwareUpgradeMACAddress, &rowreq_ctx->data.eocSoftwareUpgradeMACAddress_len,
- * eocSoftwareUpgradeMACAddress, eocSoftwareUpgradeMACAddress_len, 0)) {
- * return MFD_ERROR;
- * }
- */
- /*
- * make sure there is enough space for eocSoftwareUpgradeMACAddress data
- */
- if ((NULL == rowreq_ctx->data.eocSoftwareUpgradeMACAddress) ||
- (rowreq_ctx->data.eocSoftwareUpgradeMACAddress_len <
- (eocSoftwareUpgradeMACAddress_len* sizeof(eocSoftwareUpgradeMACAddress[0])))) {
- snmp_log(LOG_ERR,"not enough space for value\n");
- return MFD_ERROR;
- }
- rowreq_ctx->data.eocSoftwareUpgradeMACAddress_len = eocSoftwareUpgradeMACAddress_len* sizeof(eocSoftwareUpgradeMACAddress[0]);
- memcpy( rowreq_ctx->data.eocSoftwareUpgradeMACAddress, eocSoftwareUpgradeMACAddress, eocSoftwareUpgradeMACAddress_len* sizeof(eocSoftwareUpgradeMACAddress[0]) );
-
- /*
- * setup/save data for eocSoftwareUpgradeDevType
- * eocSoftwareUpgradeDevType(4)/INTEGER/ASN_INTEGER/long(u_long)//l/A/W/E/r/d/h
- */
- /*
- * TODO:246:r: |-> Define eocSoftwareUpgradeDevType mapping.
- * Map values between raw/native values and MIB values
- *
- * enums usually need mapping.
- */
- if(MFD_SUCCESS !=
- eocSoftwareUpgradeDevType_map(&rowreq_ctx->data.eocSoftwareUpgradeDevType, eocSoftwareUpgradeDevType )) {
- return MFD_ERROR;
- }
-
- /*
- * setup/save data for eocSoftwareUpgradeFileName
- * eocSoftwareUpgradeFileName(5)/OCTETSTR/ASN_OCTET_STR/char(char)//L/A/W/e/R/d/h
- */
- /*
- * TODO:246:r: |-> Define eocSoftwareUpgradeFileName mapping.
- * Map values between raw/native values and MIB values
- *
- * if(MFD_SUCCESS !=
- * eocSoftwareUpgradeFileName_map(&rowreq_ctx->data.eocSoftwareUpgradeFileName, &rowreq_ctx->data.eocSoftwareUpgradeFileName_len,
- * eocSoftwareUpgradeFileName, eocSoftwareUpgradeFileName_len, 0)) {
- * return MFD_ERROR;
- * }
- */
- /*
- * make sure there is enough space for eocSoftwareUpgradeFileName data
- */
- if ((NULL == rowreq_ctx->data.eocSoftwareUpgradeFileName) ||
- (rowreq_ctx->data.eocSoftwareUpgradeFileName_len <
- (eocSoftwareUpgradeFileName_len* sizeof(eocSoftwareUpgradeFileName[0])))) {
- snmp_log(LOG_ERR,"not enough space for value\n");
- return MFD_ERROR;
- }
- rowreq_ctx->data.eocSoftwareUpgradeFileName_len = eocSoftwareUpgradeFileName_len* sizeof(eocSoftwareUpgradeFileName[0]);
- memcpy( rowreq_ctx->data.eocSoftwareUpgradeFileName, eocSoftwareUpgradeFileName, eocSoftwareUpgradeFileName_len* sizeof(eocSoftwareUpgradeFileName[0]) );
-
- /*
- * setup/save data for eocSoftwareUpgradeProceed
- * eocSoftwareUpgradeProceed(6)/INTEGER/ASN_INTEGER/long(u_long)//l/A/W/E/r/d/h
- */
- /*
- * TODO:246:r: |-> Define eocSoftwareUpgradeProceed mapping.
- * Map values between raw/native values and MIB values
- *
- * enums usually need mapping.
- */
- if(MFD_SUCCESS !=
- eocSoftwareUpgradeProceed_map(&rowreq_ctx->data.eocSoftwareUpgradeProceed, eocSoftwareUpgradeProceed )) {
- return MFD_ERROR;
- }
-
- /*
- * setup/save data for eocSoftwareUpgradeResult
- * eocSoftwareUpgradeResult(7)/INTEGER/ASN_INTEGER/long(u_long)//l/A/w/E/r/D/h
- */
- /*
- * TODO:246:r: |-> Define eocSoftwareUpgradeResult mapping.
- * Map values between raw/native values and MIB values
- *
- * enums usually need mapping.
- */
- if(MFD_SUCCESS !=
- eocSoftwareUpgradeResult_map(&rowreq_ctx->data.eocSoftwareUpgradeResult, eocSoftwareUpgradeResult )) {
- return MFD_ERROR;
- }
-
-
+ /*
+ * TRANSIENT or semi-TRANSIENT data:
+ * copy data or save any info needed to do it in row_prep.
+ */
+ /*
+ * setup/save data for eocSoftwareUpgradeMACAddress
+ * eocSoftwareUpgradeMACAddress(3)/MacAddress/ASN_OCTET_STR/
+ * char(char)//L/A/W/e/R/d/H
+ */
+ rowreq_ctx->data.eocSoftwareUpgradeMACAddress_len = 6;
+
+ /*
+ * make sure there is enough space for eocSoftwareUpgradeMACAddress
+ * data
+ */
+ if ((NULL == rowreq_ctx->data.eocSoftwareUpgradeMACAddress) ||
+ (rowreq_ctx->data.eocSoftwareUpgradeMACAddress_len <
+ (eocSoftwareUpgradeMACAddress_len *
+ sizeof (eocSoftwareUpgradeMACAddress[0]))))
+ {
+ snmp_log (LOG_ERR, "not enough space for value\n");
+ return MFD_ERROR;
+ }
+ rowreq_ctx->data.eocSoftwareUpgradeMACAddress_len =
+ eocSoftwareUpgradeMACAddress_len *
+ sizeof (eocSoftwareUpgradeMACAddress[0]);
+ memcpy (rowreq_ctx->data.eocSoftwareUpgradeMACAddress,
+ eocSoftwareUpgradeMACAddress,
+ eocSoftwareUpgradeMACAddress_len *
+ sizeof (eocSoftwareUpgradeMACAddress[0]));
+
+ /*
+ * setup/save data for eocSoftwareUpgradeDevType
+ * eocSoftwareUpgradeDevType(4)/INTEGER/
+ *ASN_INTEGER/long(u_long)//l/A/W/E/r/d/h
+ */
+ /*
+ * TODO:246:r: |-> Define eocSoftwareUpgradeDevType mapping.
+ * Map values between raw/native values and MIB values
+ *
+ * enums usually need mapping.
+ */
+ if (MFD_SUCCESS !=
+ eocSoftwareUpgradeDevType_map (&rowreq_ctx->data.
+ eocSoftwareUpgradeDevType,
+ eocSoftwareUpgradeDevType))
+ {
+ return MFD_ERROR;
+ }
+
+ /*
+ * setup/save data for eocSoftwareUpgradeFileName
+ * eocSoftwareUpgradeFileName(5)/OCTETSTR/ASN_OCTET_STR/
+ *char(char)//L/A/W/e/R/d/h
+ */
+
+ strncpy (eocSoftwareUpgradeFileName, filename_buffer,
+ DEFAULT_SNMP_STRING_MAX_LENGTH - 1);
+ eocSoftwareUpgradeFileName[DEFAULT_SNMP_STRING_MAX_LENGTH - 1] = '\0';
+
+ eocSoftwareUpgradeFileName_len =
+ strlen (eocSoftwareUpgradeFileName) + 1;
+
+ rowreq_ctx->data.eocSoftwareUpgradeFileName_len =
+ eocSoftwareUpgradeFileName_len;
+
+ /*
+ * make sure there is enough space for eocSoftwareUpgradeFileName data
+ */
+ if ((NULL == rowreq_ctx->data.eocSoftwareUpgradeFileName) ||
+ (rowreq_ctx->data.eocSoftwareUpgradeFileName_len <
+ (eocSoftwareUpgradeFileName_len *
+ sizeof (eocSoftwareUpgradeFileName[0]))))
+ {
+ snmp_log (LOG_ERR, "not enough space for value\n");
+ return MFD_ERROR;
+ }
+ rowreq_ctx->data.eocSoftwareUpgradeFileName_len =
+ eocSoftwareUpgradeFileName_len *
+ sizeof (eocSoftwareUpgradeFileName[0]);
+ memcpy (rowreq_ctx->data.eocSoftwareUpgradeFileName,
+ eocSoftwareUpgradeFileName,
+ eocSoftwareUpgradeFileName_len *
+ sizeof (eocSoftwareUpgradeFileName[0]));
+
+ /*
+ * setup/save data for eocSoftwareUpgradeProceed
+ * eocSoftwareUpgradeProceed(6)/INTEGER/ASN_INTEGER/
+ *long(u_long)//l/A/W/E/r/d/h
+ */
+ /*
+ * TODO:246:r: |-> Define eocSoftwareUpgradeProceed mapping.
+ * Map values between raw/native values and MIB values
+ *
+ * enums usually need mapping.
+ */
+ rowreq_ctx->data.eocSoftwareUpgradeProceed =
+ eocSoftwareUpgradeProceed;
+
+ /*
+ * setup/save data for eocSoftwareUpgradeResult
+ * eocSoftwareUpgradeResult(7)/INTEGER/ASN_INTEGER/
+ *long(u_long)//l/A/w/E/r/D/h
+ */
+ /*
+ * TODO:246:r: |-> Define eocSoftwareUpgradeResult mapping.
+ * Map values between raw/native values and MIB values
+ *
+ * enums usually need mapping.
+ */
+ if (MFD_SUCCESS !=
+ eocSoftwareUpgradeResult_map (&rowreq_ctx->data.
+ eocSoftwareUpgradeResult,
+ eocSoftwareUpgradeResult
+ [eocSoftwareUpgradeCNUIndex]))
+ {
+ return MFD_ERROR;
+ }
+
+
/*
* insert into table container
*/
@@ -352,7 +667,8 @@ eocSoftwareUpgradeTable_container_load(netsnmp_container *container)
++count;
}
- DEBUGMSGT(("verbose:eocSoftwareUpgradeTable:eocSoftwareUpgradeTable_container_load",
+ DEBUGMSGT(("verbose:eocSoftwareUpgradeTable:",
+ "eocSoftwareUpgradeTable_container_load",
"inserted %d records\n", count));
return MFD_SUCCESS;
diff --git a/cleopatre/application/spidnetsnmp/agent/mibgroup/mstar-eoc-mib/eocSoftwareUpgradeGroup/eocSoftwareUpgradeTable/eocSoftwareUpgradeTable_data_set.c b/cleopatre/application/spidnetsnmp/agent/mibgroup/mstar-eoc-mib/eocSoftwareUpgradeGroup/eocSoftwareUpgradeTable/eocSoftwareUpgradeTable_data_set.c
index 0af8c144db..d76b9df346 100644
--- a/cleopatre/application/spidnetsnmp/agent/mibgroup/mstar-eoc-mib/eocSoftwareUpgradeGroup/eocSoftwareUpgradeTable/eocSoftwareUpgradeTable_data_set.c
+++ b/cleopatre/application/spidnetsnmp/agent/mibgroup/mstar-eoc-mib/eocSoftwareUpgradeGroup/eocSoftwareUpgradeTable/eocSoftwareUpgradeTable_data_set.c
@@ -13,12 +13,29 @@
/* include our parent header */
#include "eocSoftwareUpgradeTable.h"
+/* directory for temporary storage of master image */
+#define MASTER_IMG_DIR "/tmp"
+
+/* mutex protecting container for reload */
+static pthread_mutex_t mutex_reload;
+
+/* indication of active master image download */
+static int dl_active = 0;
+
+/* mutex protecting download indication */
+static pthread_mutex_t mutex_dl;
+
+/* download master image file with given filename from server (server parameters are read from configuration files) */
+int eocSoftwareUpgrade_server_download (char *filename);
+
+/* thread for master upgrade action */
+void *eocSoftwareUpgrade_thread (void *arg);
/** @defgroup data_set data_set: Routines to set data
*
* These routines are used to set the value for individual objects. The
* row context is passed, along with the new value.
- *
+ *
* @{
*/
/**********************************************************************
@@ -260,72 +277,46 @@ eocSoftwareUpgradeTable_commit( eocSoftwareUpgradeTable_rowreq_ctx *rowreq_ctx)
* 3) set the column's flag in column_set_flags if it needs undo
* processing in case of a failure.
*/
- if (save_flags & COLUMN_EOCSOFTWAREUPGRADEMACADDRESS_FLAG) {
- save_flags &= ~COLUMN_EOCSOFTWAREUPGRADEMACADDRESS_FLAG; /* clear eocSoftwareUpgradeMACAddress */
- /*
- * TODO:482:o: |-> commit column eocSoftwareUpgradeMACAddress.
- */
- rc = -1;
- if(-1 == rc) {
- snmp_log(LOG_ERR,"eocSoftwareUpgradeTable column eocSoftwareUpgradeMACAddress commit failed\n");
- }
- else {
- /*
- * set flag, in case we need to undo eocSoftwareUpgradeMACAddress
- */
- rowreq_ctx->column_set_flags |= COLUMN_EOCSOFTWAREUPGRADEMACADDRESS_FLAG;
- }
+ if (save_flags & COLUMN_EOCSOFTWAREUPGRADEMACADDRESS_FLAG)
+ {
+ save_flags &= ~COLUMN_EOCSOFTWAREUPGRADEMACADDRESS_FLAG;
+ /* clear eocSoftwareUpgradeMACAddress */
+ /*
+ * set flag, in case we need to undo eocSoftwareUpgradeMACAddress
+ */
+ rowreq_ctx->column_set_flags |=
+ COLUMN_EOCSOFTWAREUPGRADEMACADDRESS_FLAG;
}
- if (save_flags & COLUMN_EOCSOFTWAREUPGRADEDEVTYPE_FLAG) {
- save_flags &= ~COLUMN_EOCSOFTWAREUPGRADEDEVTYPE_FLAG; /* clear eocSoftwareUpgradeDevType */
- /*
- * TODO:482:o: |-> commit column eocSoftwareUpgradeDevType.
- */
- rc = -1;
- if(-1 == rc) {
- snmp_log(LOG_ERR,"eocSoftwareUpgradeTable column eocSoftwareUpgradeDevType commit failed\n");
- }
- else {
- /*
- * set flag, in case we need to undo eocSoftwareUpgradeDevType
- */
- rowreq_ctx->column_set_flags |= COLUMN_EOCSOFTWAREUPGRADEDEVTYPE_FLAG;
- }
+ if (save_flags & COLUMN_EOCSOFTWAREUPGRADEDEVTYPE_FLAG)
+ {
+ save_flags &= ~COLUMN_EOCSOFTWAREUPGRADEDEVTYPE_FLAG;
+ /* clear eocSoftwareUpgradeDevType */
+ /*
+ *set flag, in case we need to undo eocSoftwareUpgradeDevType
+ */
+ rowreq_ctx->column_set_flags |= COLUMN_EOCSOFTWAREUPGRADEDEVTYPE_FLAG;
}
- if (save_flags & COLUMN_EOCSOFTWAREUPGRADEFILENAME_FLAG) {
- save_flags &= ~COLUMN_EOCSOFTWAREUPGRADEFILENAME_FLAG; /* clear eocSoftwareUpgradeFileName */
- /*
- * TODO:482:o: |-> commit column eocSoftwareUpgradeFileName.
- */
- rc = -1;
- if(-1 == rc) {
- snmp_log(LOG_ERR,"eocSoftwareUpgradeTable column eocSoftwareUpgradeFileName commit failed\n");
- }
- else {
- /*
- * set flag, in case we need to undo eocSoftwareUpgradeFileName
- */
- rowreq_ctx->column_set_flags |= COLUMN_EOCSOFTWAREUPGRADEFILENAME_FLAG;
- }
+ if (save_flags & COLUMN_EOCSOFTWAREUPGRADEFILENAME_FLAG)
+ {
+ save_flags &= ~COLUMN_EOCSOFTWAREUPGRADEFILENAME_FLAG;
+ /* clear eocSoftwareUpgradeFileName */
+ /*
+ * set flag, in case we need to undo eocSoftwareUpgradeFileName
+ */
+ rowreq_ctx->column_set_flags |=
+ COLUMN_EOCSOFTWAREUPGRADEFILENAME_FLAG;
}
- if (save_flags & COLUMN_EOCSOFTWAREUPGRADEPROCEED_FLAG) {
- save_flags &= ~COLUMN_EOCSOFTWAREUPGRADEPROCEED_FLAG; /* clear eocSoftwareUpgradeProceed */
- /*
- * TODO:482:o: |-> commit column eocSoftwareUpgradeProceed.
- */
- rc = -1;
- if(-1 == rc) {
- snmp_log(LOG_ERR,"eocSoftwareUpgradeTable column eocSoftwareUpgradeProceed commit failed\n");
- }
- else {
- /*
- * set flag, in case we need to undo eocSoftwareUpgradeProceed
- */
- rowreq_ctx->column_set_flags |= COLUMN_EOCSOFTWAREUPGRADEPROCEED_FLAG;
- }
+ if (save_flags & COLUMN_EOCSOFTWAREUPGRADEPROCEED_FLAG)
+ {
+ save_flags &= ~COLUMN_EOCSOFTWAREUPGRADEPROCEED_FLAG;
+ /* clear eocSoftwareUpgradeProceed */
+ /*
+ * set flag, in case we need to undo eocSoftwareUpgradeProceed
+ */
+ rowreq_ctx->column_set_flags |= COLUMN_EOCSOFTWAREUPGRADEPROCEED_FLAG;
}
/*
@@ -336,7 +327,7 @@ eocSoftwareUpgradeTable_commit( eocSoftwareUpgradeTable_rowreq_ctx *rowreq_ctx)
}
if (save_flags) {
- snmp_log(LOG_ERR, "unhandled columns (0x%x) in commit\n", save_flags);
+ snmp_log (LOG_ERR, "unhandled columns (0x%x) in commit\n", save_flags);
return MFD_ERROR;
}
@@ -376,7 +367,7 @@ eocSoftwareUpgradeTable_undo_commit( eocSoftwareUpgradeTable_rowreq_ctx *rowreq_
* eg: if (rowreq_ctx->column_set_flags & COLUMN__FLAG) {}
*/
-
+
/*
* if we successfully un-commited this row, clear the dirty flag.
*/
@@ -434,12 +425,12 @@ eocSoftwareUpgradeTable_undo_commit( eocSoftwareUpgradeTable_rowreq_ctx *rowreq_
* You should check that the requested change between the undo value and the
* new value is legal (ie, the transistion from one value to another
* is legal).
- *
+ *
*@note
* This check is only to determine if the new value
* is \b potentially valid. This is the first check of many, and
* is one of the simplest ones.
- *
+ *
*@note
* this is not the place to do any checks for values
* which depend on some other value in the mib. Those
@@ -533,21 +524,9 @@ eocSoftwareUpgradeMACAddress_set( eocSoftwareUpgradeTable_rowreq_ctx *rowreq_ctx
netsnmp_assert(NULL != rowreq_ctx);
netsnmp_assert(NULL != eocSoftwareUpgradeMACAddress_val_ptr);
-/*
- * TODO:245:o: |-> Implement eocSoftwareUpgradeMACAddress reverse mapping.
- * If the values for your data type don't exactly match the
- * possible values defined by the mib, you should map them here.
- */
- /*
- * TODO:461:M: |-> Set eocSoftwareUpgradeMACAddress value.
- * set eocSoftwareUpgradeMACAddress value in rowreq_ctx->data
- */
- memcpy( rowreq_ctx->data.eocSoftwareUpgradeMACAddress, eocSoftwareUpgradeMACAddress_val_ptr, eocSoftwareUpgradeMACAddress_val_ptr_len );
- /** convert bytes to number of char */
- rowreq_ctx->data.eocSoftwareUpgradeMACAddress_len = eocSoftwareUpgradeMACAddress_val_ptr_len / sizeof(eocSoftwareUpgradeMACAddress_val_ptr[0]);
-
+ snmp_log (LOG_ERR, "SET not supported for SoftwareUpgradeMACAddress!\n");
- return MFD_SUCCESS;
+ return SNMP_ERR_NOTWRITABLE;
} /* eocSoftwareUpgradeMACAddress_set */
/**
@@ -575,7 +554,7 @@ eocSoftwareUpgradeMACAddress_undo( eocSoftwareUpgradeTable_rowreq_ctx *rowreq_ct
(rowreq_ctx->undo->eocSoftwareUpgradeMACAddress_len * sizeof(rowreq_ctx->data.eocSoftwareUpgradeMACAddress[0])));
rowreq_ctx->data.eocSoftwareUpgradeMACAddress_len = rowreq_ctx->undo->eocSoftwareUpgradeMACAddress_len;
-
+
return MFD_SUCCESS;
} /* eocSoftwareUpgradeMACAddress_undo */
@@ -623,12 +602,12 @@ eocSoftwareUpgradeMACAddress_undo( eocSoftwareUpgradeTable_rowreq_ctx *rowreq_ct
* You should check that the requested change between the undo value and the
* new value is legal (ie, the transistion from one value to another
* is legal).
- *
+ *
*@note
* This check is only to determine if the new value
* is \b potentially valid. This is the first check of many, and
* is one of the simplest ones.
- *
+ *
*@note
* this is not the place to do any checks for values
* which depend on some other value in the mib. Those
@@ -720,49 +699,9 @@ eocSoftwareUpgradeDevType_set( eocSoftwareUpgradeTable_rowreq_ctx *rowreq_ctx, u
* If the values for your data type don't exactly match the
* possible values defined by the mib, you should map them here.
*/
- /*
- ***************************************************
- *** START EXAMPLE CODE ***
- ***---------------------------------------------***/
- switch(eocSoftwareUpgradeDevType_val) {
- case EOCSOFTWAREUPGRADEDEVTYPE_CBAT:
- rowreq_ctx->data.eocSoftwareUpgradeDevType = INTERNAL_EOCSOFTWAREUPGRADETABLE_EOCSOFTWAREUPGRADEDEVTYPE_CBAT;
- break;
-
- case EOCSOFTWAREUPGRADEDEVTYPE_CBAT_CARD:
- rowreq_ctx->data.eocSoftwareUpgradeDevType = INTERNAL_EOCSOFTWAREUPGRADETABLE_EOCSOFTWAREUPGRADEDEVTYPE_CBAT_CARD;
- break;
-
- case EOCSOFTWAREUPGRADEDEVTYPE_CNU:
- rowreq_ctx->data.eocSoftwareUpgradeDevType = INTERNAL_EOCSOFTWAREUPGRADETABLE_EOCSOFTWAREUPGRADEDEVTYPE_CNU;
- break;
-
- case EOCSOFTWAREUPGRADEDEVTYPE_OTHER:
- rowreq_ctx->data.eocSoftwareUpgradeDevType = INTERNAL_EOCSOFTWAREUPGRADETABLE_EOCSOFTWAREUPGRADEDEVTYPE_OTHER;
- break;
-
- case EOCSOFTWAREUPGRADEDEVTYPE_RESERVED1:
- rowreq_ctx->data.eocSoftwareUpgradeDevType = INTERNAL_EOCSOFTWAREUPGRADETABLE_EOCSOFTWAREUPGRADEDEVTYPE_RESERVED1;
- break;
-
- case EOCSOFTWAREUPGRADEDEVTYPE_RESERVED2:
- rowreq_ctx->data.eocSoftwareUpgradeDevType = INTERNAL_EOCSOFTWAREUPGRADETABLE_EOCSOFTWAREUPGRADEDEVTYPE_RESERVED2;
- break;
-
- case EOCSOFTWAREUPGRADEDEVTYPE_RESERVED3:
- rowreq_ctx->data.eocSoftwareUpgradeDevType = INTERNAL_EOCSOFTWAREUPGRADETABLE_EOCSOFTWAREUPGRADEDEVTYPE_RESERVED3;
- break;
-
- default:
- snmp_log(LOG_ERR, "couldn't reverse map value %ld for eocSoftwareUpgradeDevType\n", eocSoftwareUpgradeDevType_val );
- return SNMP_ERR_GENERR;
- }
- /*
- ***---------------------------------------------***
- *** END EXAMPLE CODE ***
- ***************************************************/
+ snmp_log (LOG_ERR, "SET not supported for SoftwareUpgradeDevType!\n");
- return MFD_SUCCESS;
+ return SNMP_ERR_NOTWRITABLE;
} /* eocSoftwareUpgradeDevType_set */
/**
@@ -788,7 +727,7 @@ eocSoftwareUpgradeDevType_undo( eocSoftwareUpgradeTable_rowreq_ctx *rowreq_ctx)
*/
rowreq_ctx->data.eocSoftwareUpgradeDevType = rowreq_ctx->undo->eocSoftwareUpgradeDevType;
-
+
return MFD_SUCCESS;
} /* eocSoftwareUpgradeDevType_undo */
@@ -832,12 +771,12 @@ eocSoftwareUpgradeDevType_undo( eocSoftwareUpgradeTable_rowreq_ctx *rowreq_ctx)
* You should check that the requested change between the undo value and the
* new value is legal (ie, the transistion from one value to another
* is legal).
- *
+ *
*@note
* This check is only to determine if the new value
* is \b potentially valid. This is the first check of many, and
* is one of the simplest ones.
- *
+ *
*@note
* this is not the place to do any checks for values
* which depend on some other value in the mib. Those
@@ -855,6 +794,7 @@ eocSoftwareUpgradeDevType_undo( eocSoftwareUpgradeTable_rowreq_ctx *rowreq_ctx)
int
eocSoftwareUpgradeFileName_check_value( eocSoftwareUpgradeTable_rowreq_ctx *rowreq_ctx, char *eocSoftwareUpgradeFileName_val_ptr, size_t eocSoftwareUpgradeFileName_val_ptr_len)
{
+ int current_index;
DEBUGMSGTL(("verbose:eocSoftwareUpgradeTable:eocSoftwareUpgradeFileName_check_value","called\n"));
/** should never get a NULL pointer */
@@ -864,6 +804,31 @@ eocSoftwareUpgradeFileName_check_value( eocSoftwareUpgradeTable_rowreq_ctx *rowr
/*
* TODO:441:o: |-> Check for valid eocSoftwareUpgradeFileName value.
*/
+ /* if master upgrade or image download is active, do not allow changing file name */
+ if (rowreq_ctx->data.eocSoftwareUpgradeDevType ==
+ EOCSOFTWAREUPGRADEDEVTYPE_CBAT)
+ {
+ if ((dl_active == 1) ||
+ (eocSoftwareUpgradeResult[0] ==
+ INTERNAL_EOCSOFTWAREUPGRADETABLE_EOCSOFTWAREUPGRADERESULT_UPLOADING))
+ {
+ snmp_log (LOG_ERR, "cannot change master filename while upgrade"
+ " or transfer is active\n");
+ return SNMP_ERR_INCONSISTENTVALUE;
+ }
+ }
+ else if (rowreq_ctx->data.eocSoftwareUpgradeDevType ==
+ EOCSOFTWAREUPGRADEDEVTYPE_CNU)
+ {
+ current_index = rowreq_ctx->tbl_idx.eocSoftwareUpgradeCNUIndex;
+ if (eocSoftwareUpgradeResult[current_index] ==
+ INTERNAL_EOCSOFTWAREUPGRADETABLE_EOCSOFTWAREUPGRADERESULT_UPLOADING)
+ {
+ snmp_log (LOG_ERR, "cannot change slave filename while"
+ " transfer is active\n");
+ return SNMP_ERR_INCONSISTENTVALUE;
+ }
+ }
return MFD_SUCCESS; /* eocSoftwareUpgradeFileName value not illegal */
} /* eocSoftwareUpgradeFileName_check_value */
@@ -924,8 +889,17 @@ eocSoftwareUpgradeFileName_undo_setup( eocSoftwareUpgradeTable_rowreq_ctx *rowre
int
eocSoftwareUpgradeFileName_set( eocSoftwareUpgradeTable_rowreq_ctx *rowreq_ctx, char *eocSoftwareUpgradeFileName_val_ptr, size_t eocSoftwareUpgradeFileName_val_ptr_len )
{
-
- DEBUGMSGTL(("verbose:eocSoftwareUpgradeTable:eocSoftwareUpgradeFileName_set","called\n"));
+ char buffer[LIBSPID_LINE_MAX_LEN];
+ const char delimiter = LIBSPID_UPDATE_INFO_DELIMITER[0];
+ char *elt_buffer[LIBSPID_ELT_MAX_NB];
+
+ int ret;
+ char mac_str[LIBSPID_MAC_STR_LEN];
+ char action_string[2];
+ char action_last_string[2];
+ char result_string[2];
+ DEBUGMSGTL(("verbose:eocSoftwareUpgradeTable:",
+ "eocSoftwareUpgradeFileName_set","called\n"));
/** should never get a NULL pointer */
netsnmp_assert(NULL != rowreq_ctx);
@@ -936,13 +910,76 @@ eocSoftwareUpgradeFileName_set( eocSoftwareUpgradeTable_rowreq_ctx *rowreq_ctx,
* If the values for your data type don't exactly match the
* possible values defined by the mib, you should map them here.
*/
+ /* copy SET request variable buffer and add terminal 0 */
+ strncpy (buffer, eocSoftwareUpgradeFileName_val_ptr,
+ eocSoftwareUpgradeFileName_val_ptr_len);
+ buffer[eocSoftwareUpgradeFileName_val_ptr_len] = '\0';
+
+ if (rowreq_ctx->data.eocSoftwareUpgradeDevType ==
+ EOCSOFTWAREUPGRADEDEVTYPE_CBAT)
+ {
+ if (LIBSPID_SUCCESS !=
+ libspid_config_write_item (
+ LIBSPID_SYSTEM_CONF_PATH,
+ LIBSPID_SYSTEM_CONF_LABEL_UPGRADE_MASTER_FILENAME,
+ buffer))
+ {
+ snmp_log (LOG_ERR, "libspid_config_write_item error\n");
+ return SNMP_ERR_COMMITFAILED;
+ }
+ }
+ else if (rowreq_ctx->data.eocSoftwareUpgradeDevType ==
+ EOCSOFTWAREUPGRADEDEVTYPE_CNU)
+ {
+ /* convert MAC address from bin to string */
+ ret =
+ libspid_mac_bin_to_str (rowreq_ctx->data.
+ eocSoftwareUpgradeMACAddress, mac_str);
+ if (LIBSPID_SUCCESS != ret)
+ {
+ snmp_log (LOG_ERR, "libspid_mac_bin_to_str error\n");
+ return SNMP_ERR_COMMITFAILED;
+ }
+
+ elt_buffer[0] = buffer;
+ /* initialize action and result field to none */
+ sprintf (action_string, "%d", LIBSPID_UPDATE_ACTION_NONE);
+ sprintf (result_string, "%d", LIBSPID_UPDATE_NONE);
+ sprintf (action_last_string, "%d", LIBSPID_UPDATE_ACTION_NONE);
+ elt_buffer[1] = action_string;
+ elt_buffer[2] = result_string;
+ elt_buffer[3] = action_last_string;
+
+ /* write MAC, filename and actions to update.info file */
+ ret = libspid_config_write_line (LIBSPID_UPDATE_INFO_PATH,
+ delimiter, mac_str, 4, elt_buffer);
+
+ if (LIBSPID_SUCCESS != ret)
+ {
+ snmp_log (LOG_ERR, "libspid_config_write_line error\n");
+ return SNMP_ERR_COMMITFAILED;
+ }
+
+ /* save update file to flash */
+ ret = libspid_system_save_file (LIBSPID_UPDATE_INFO_PATH);
+ if (LIBSPID_SUCCESS != ret)
+ {
+ snmp_log (LOG_ERR, "libspid_system_save_file error\n");
+ return SNMP_ERR_COMMITFAILED;
+ }
+ }
+
/*
* TODO:461:M: |-> Set eocSoftwareUpgradeFileName value.
* set eocSoftwareUpgradeFileName value in rowreq_ctx->data
*/
- memcpy( rowreq_ctx->data.eocSoftwareUpgradeFileName, eocSoftwareUpgradeFileName_val_ptr, eocSoftwareUpgradeFileName_val_ptr_len );
+ memcpy (rowreq_ctx->data.eocSoftwareUpgradeFileName,
+ eocSoftwareUpgradeFileName_val_ptr,
+ eocSoftwareUpgradeFileName_val_ptr_len);
/** convert bytes to number of char */
- rowreq_ctx->data.eocSoftwareUpgradeFileName_len = eocSoftwareUpgradeFileName_val_ptr_len / sizeof(eocSoftwareUpgradeFileName_val_ptr[0]);
+ rowreq_ctx->data.eocSoftwareUpgradeFileName_len =
+ eocSoftwareUpgradeFileName_val_ptr_len /
+ sizeof (eocSoftwareUpgradeFileName_val_ptr[0]);
return MFD_SUCCESS;
@@ -957,23 +994,81 @@ eocSoftwareUpgradeFileName_set( eocSoftwareUpgradeTable_rowreq_ctx *rowreq_ctx,
int
eocSoftwareUpgradeFileName_undo( eocSoftwareUpgradeTable_rowreq_ctx *rowreq_ctx)
{
+ int ret;
+ char buffer[LIBSPID_LINE_MAX_LEN];
+ char mac_str[LIBSPID_MAC_STR_LEN];
- DEBUGMSGTL(("verbose:eocSoftwareUpgradeTable:eocSoftwareUpgradeFileName_undo","called\n"));
+ DEBUGMSGTL(("verbose:eocSoftwareUpgradeTable:",
+ "eocSoftwareUpgradeFileName_undo","called\n"));
netsnmp_assert(NULL != rowreq_ctx);
+ /* copy UNDO variable buffer and add terminal 0 */
+ strncpy (buffer, rowreq_ctx->undo->eocSoftwareUpgradeFileName,
+ rowreq_ctx->undo->eocSoftwareUpgradeFileName_len);
+ buffer[rowreq_ctx->undo->eocSoftwareUpgradeFileName_len] = '\0';
+
+ if (rowreq_ctx->data.eocSoftwareUpgradeDevType ==
+ EOCSOFTWAREUPGRADEDEVTYPE_CBAT)
+ {
+ if (LIBSPID_SUCCESS !=
+ libspid_config_write_item (
+ LIBSPID_SYSTEM_CONF_PATH,
+ LIBSPID_SYSTEM_CONF_LABEL_UPGRADE_MASTER_FILENAME,
+ buffer))
+ {
+ snmp_log (LOG_ERR, "libspid_config_write_item error\n");
+ return SNMP_ERR_UNDOFAILED;
+ }
+ }
+ else if (rowreq_ctx->data.eocSoftwareUpgradeDevType ==
+ EOCSOFTWAREUPGRADEDEVTYPE_CNU)
+ {
+ /* convert MAC address from bin to string */
+ ret = libspid_mac_bin_to_str (
+ rowreq_ctx->data.eocSoftwareUpgradeMACAddress,
+ mac_str);
+ if (LIBSPID_SUCCESS != ret)
+ {
+ snmp_log (LOG_ERR, "libspid_mac_bin_to_str error\n");
+ return SNMP_ERR_UNDOFAILED;
+ }
+
+ /* if commit fails, remove line from update.info (if existing) */
+ ret = libspid_config_remove_line (LIBSPID_UPDATE_INFO_PATH,
+ LIBSPID_UPDATE_INFO_DELIMITER,
+ mac_str);
+ if ((LIBSPID_SUCCESS != ret) && (LIBSPID_ERROR_NOT_FOUND != ret))
+ {
+ snmp_log (LOG_ERR, "libspid_config_remove_item error\n");
+ return SNMP_ERR_UNDOFAILED;
+ }
+
+ /* save update file to flash */
+ ret = libspid_system_save_file (LIBSPID_UPDATE_INFO_PATH);
+ if (LIBSPID_SUCCESS != ret)
+ {
+ snmp_log (LOG_ERR, "libspid_system_save_file error\n");
+ return SNMP_ERR_UNDOFAILED;
+ }
+ }
+
/*
* TODO:456:o: |-> Clean up eocSoftwareUpgradeFileName undo.
*/
/*
* copy eocSoftwareUpgradeFileName and eocSoftwareUpgradeFileName_len data
- * set rowreq_ctx->data.eocSoftwareUpgradeFileName from rowreq_ctx->undo->eocSoftwareUpgradeFileName
+ * set rowreq_ctx->data.eocSoftwareUpgradeFileName from
+ *rowreq_ctx->undo->eocSoftwareUpgradeFileName
*/
- memcpy( rowreq_ctx->data.eocSoftwareUpgradeFileName, rowreq_ctx->undo->eocSoftwareUpgradeFileName,
- (rowreq_ctx->undo->eocSoftwareUpgradeFileName_len * sizeof(rowreq_ctx->data.eocSoftwareUpgradeFileName[0])));
- rowreq_ctx->data.eocSoftwareUpgradeFileName_len = rowreq_ctx->undo->eocSoftwareUpgradeFileName_len;
+ memcpy (rowreq_ctx->data.eocSoftwareUpgradeFileName,
+ rowreq_ctx->undo->eocSoftwareUpgradeFileName,
+ (rowreq_ctx->undo->eocSoftwareUpgradeFileName_len *
+ sizeof (rowreq_ctx->data.eocSoftwareUpgradeFileName[0])));
+ rowreq_ctx->data.eocSoftwareUpgradeFileName_len =
+ rowreq_ctx->undo->eocSoftwareUpgradeFileName_len;
+
-
return MFD_SUCCESS;
} /* eocSoftwareUpgradeFileName_undo */
@@ -1017,12 +1112,12 @@ eocSoftwareUpgradeFileName_undo( eocSoftwareUpgradeTable_rowreq_ctx *rowreq_ctx)
* You should check that the requested change between the undo value and the
* new value is legal (ie, the transistion from one value to another
* is legal).
- *
+ *
*@note
* This check is only to determine if the new value
* is \b potentially valid. This is the first check of many, and
* is one of the simplest ones.
- *
+ *
*@note
* this is not the place to do any checks for values
* which depend on some other value in the mib. Those
@@ -1103,42 +1198,299 @@ eocSoftwareUpgradeProceed_undo_setup( eocSoftwareUpgradeTable_rowreq_ctx *rowreq
int
eocSoftwareUpgradeProceed_set( eocSoftwareUpgradeTable_rowreq_ctx *rowreq_ctx, u_long eocSoftwareUpgradeProceed_val )
{
+ int ret;
+ pthread_t tid;
+ pthread_attr_t attr;
+
+ int current_index;
+ char mac_str[LIBSPID_MAC_STR_LEN];
+
+ char filename[DEFAULT_SNMP_STRING_MAX_LENGTH];
+ int filename_len;
- DEBUGMSGTL(("verbose:eocSoftwareUpgradeTable:eocSoftwareUpgradeProceed_set","called\n"));
+ const char delimiter = LIBSPID_UPDATE_INFO_DELIMITER[0];
+ char *elt_buffer[LIBSPID_ELT_MAX_NB];
+
+ char action_string[2];
+ char action_last_string[2];
+ char result_string[2];
+
+ DEBUGMSGTL(("verbose:eocSoftwareUpgradeTable:",
+ "eocSoftwareUpgradeProceed_set", "called\n"));
/** should never get a NULL pointer */
netsnmp_assert(NULL != rowreq_ctx);
+ /* initialize mutexes */
+ pthread_mutex_init (&mutex_reload, NULL);
+ pthread_mutex_init (&mutex_dl, NULL);
+
+ /* initialize thread attributes */
+ pthread_attr_init (&attr);
+ pthread_attr_setdetachstate (&attr, PTHREAD_CREATE_DETACHED);
+
/*
* TODO:245:o: |-> Implement eocSoftwareUpgradeProceed reverse mapping.
* If the values for your data type don't exactly match the
* possible values defined by the mib, you should map them here.
*/
- /*
- ***************************************************
- *** START EXAMPLE CODE ***
- ***---------------------------------------------***/
- switch(eocSoftwareUpgradeProceed_val) {
+
+ /* save value of current master or slave index -
+ to be preserved in case container is reloaded */
+ current_index = rowreq_ctx->tbl_idx.eocSoftwareUpgradeCNUIndex;
+
+ if (0 == current_index)
+ {
+ switch (eocSoftwareUpgradeProceed_val)
+ {
case EOCSOFTWAREUPGRADEPROCEED_DOWNLOAD:
- rowreq_ctx->data.eocSoftwareUpgradeProceed = INTERNAL_EOCSOFTWAREUPGRADETABLE_EOCSOFTWAREUPGRADEPROCEED_DOWNLOAD;
- break;
+ /* download action not supported for master */
+ snmp_log (LOG_ERR, "eocSoftwareUpgradeProceed_set: Download"
+ " action not supported for master!\n");
+ return SNMP_ERR_INCONSISTENTVALUE;
+
+
+ case EOCSOFTWAREUPGRADEPROCEED_UPLOAD:
+ /* upload action not supported for master */
+ snmp_log (LOG_ERR, "eocSoftwareUpgradeProceed_set: Upload action"
+ " not supported for master!\n");
+ return SNMP_ERR_INCONSISTENTVALUE;
case EOCSOFTWAREUPGRADEPROCEED_UPGRADE:
- rowreq_ctx->data.eocSoftwareUpgradeProceed = INTERNAL_EOCSOFTWAREUPGRADETABLE_EOCSOFTWAREUPGRADEPROCEED_UPGRADE;
- break;
+ if (INTERNAL_EOCSOFTWAREUPGRADETABLE_EOCSOFTWAREUPGRADERESULT_UPGRADING
+ != eocSoftwareUpgradeResult[current_index])
+ {
+ rowreq_ctx->data.eocSoftwareUpgradeProceed =
+ INTERNAL_EOCSOFTWAREUPGRADETABLE_EOCSOFTWAREUPGRADEPROCEED_UPGRADE;
+ /* call thread for upgrading master image */
+ pthread_create (&tid, &attr,
+ eocSoftwareUpgrade_thread, rowreq_ctx);
+
+ }
+ else
+ {
+ snmp_log (LOG_ERR, "eocSoftwareUpgradeProceed_set: Another "
+ "upgrade action already running for master!\n");
+ return SNMP_ERR_RESOURCEUNAVAILABLE;
+ }
+ break;
+
+ default:
+ snmp_log (LOG_ERR, "couldn't reverse map value %ld for"
+ " eocSoftwareUpgradeProceed\n",
+ eocSoftwareUpgradeProceed_val);
+ return SNMP_ERR_GENERR;
+ }
+ }
+ else
+ {
+ switch (eocSoftwareUpgradeProceed_val)
+ {
+ case EOCSOFTWAREUPGRADEPROCEED_DOWNLOAD:
+ /* download action not supported for slave */
+ snmp_log (LOG_ERR, "eocSoftwareUpgradeProceed_set: Download "
+ "action not supported for slave!\n");
+ return SNMP_ERR_INCONSISTENTVALUE;
+
case EOCSOFTWAREUPGRADEPROCEED_UPLOAD:
- rowreq_ctx->data.eocSoftwareUpgradeProceed = INTERNAL_EOCSOFTWAREUPGRADETABLE_EOCSOFTWAREUPGRADEPROCEED_UPLOAD;
- break;
+ if (INTERNAL_EOCSOFTWAREUPGRADETABLE_EOCSOFTWAREUPGRADERESULT_UPLOADING
+ != eocSoftwareUpgradeResult[current_index])
+ {
+ rowreq_ctx->data.eocSoftwareUpgradeProceed =
+ INTERNAL_EOCSOFTWAREUPGRADETABLE_EOCSOFTWAREUPGRADEPROCEED_UPLOAD;
+
+ /* convert MAC address from bin to string */
+ ret = libspid_mac_bin_to_str (
+ rowreq_ctx->data.eocSoftwareUpgradeMACAddress,
+ mac_str);
+ if (LIBSPID_SUCCESS != ret)
+ {
+ snmp_log (LOG_ERR, "libspid_mac_bin_to_str error\n");
+ eocSoftwareUpgradeResult[current_index] =
+ INTERNAL_EOCSOFTWAREUPGRADETABLE_EOCSOFTWAREUPGRADERESULT_UPLOADFAILED;
+ /* set upgrade result in row request context
+ (to be updated before container reload) */
+ rowreq_ctx->data.eocSoftwareUpgradeResult =
+ INTERNAL_EOCSOFTWAREUPGRADETABLE_EOCSOFTWAREUPGRADERESULT_UPLOADFAILED;
+ return SNMP_ERR_COMMITFAILED;
+ }
+ DEBUGMSGTL (("verbose:eocSoftwareUpgradeTable:",
+ "eocSoftwareUpgradeProceed_set",
+ "slave MAC address: |%s|\n", mac_str));
+
+ /* copy current slave filename - to be preserved
+ in case container is reloaded */
+ filename_len =
+ rowreq_ctx->data.eocSoftwareUpgradeFileName_len;
+ strncpy (filename,
+ rowreq_ctx->data.eocSoftwareUpgradeFileName,
+ filename_len);
+ filename[filename_len] = '\0';
+
+ DEBUGMSGTL (("verbose:eocSoftwareUpgradeTable:",
+ "eocSoftwareUpgradeProceed_set",
+ "slave filename: |%s|\n", filename));
+
+ /* denote upload action field for current slave in update.info
+ file and set status field to running */
+ elt_buffer[0] = filename;
+ sprintf (action_string, "%d", LIBSPID_UPDATE_ACTION_UPLOAD);
+ sprintf (result_string, "%d", LIBSPID_UPDATE_RUNNING);
+ sprintf (action_last_string, "%d",
+ LIBSPID_UPDATE_ACTION_UPLOAD);
+ elt_buffer[1] = action_string;
+ elt_buffer[2] = result_string;
+ elt_buffer[3] = action_last_string;
+
+ /* write MAC, filename and actions to update.info file */
+ ret = libspid_config_write_line (LIBSPID_UPDATE_INFO_PATH,
+ delimiter, mac_str,
+ 4, elt_buffer);
+ if (LIBSPID_SUCCESS != ret)
+ {
+ snmp_log (LOG_ERR, "libspid_config_write_line error\n");
+ return SNMP_ERR_COMMITFAILED;
+ }
+
+ /* save update file path to flash */
+ ret = libspid_system_save_file (LIBSPID_UPDATE_INFO_PATH);
+ if (LIBSPID_SUCCESS != ret)
+ {
+ snmp_log (LOG_ERR, "libspid_system_save_file error\n");
+ return SNMP_ERR_COMMITFAILED;
+ }
+ else
+ {
+ /* set internal upgrade status to running in result array
+ * (to be preserved in case container is reloaded) */
+ eocSoftwareUpgradeResult[current_index] =
+ INTERNAL_EOCSOFTWAREUPGRADETABLE_EOCSOFTWAREUPGRADERESULT_UPLOADING;
+
+ /*
+ * set internal upgrade status to running in row request
+ * context
+ * (to be updated before container reload)
+ */
+ rowreq_ctx->data.eocSoftwareUpgradeResult =
+ INTERNAL_EOCSOFTWAREUPGRADETABLE_EOCSOFTWAREUPGRADERESULT_UPLOADING;
+ }
+ }
+ else
+ {
+ snmp_log (LOG_ERR, "eocSoftwareUpgradeProceed_set: Another"
+ " upload action already running for selected"
+ " slave!\n");
+ return SNMP_ERR_RESOURCEUNAVAILABLE;
+ }
+ break;
- default:
- snmp_log(LOG_ERR, "couldn't reverse map value %ld for eocSoftwareUpgradeProceed\n", eocSoftwareUpgradeProceed_val );
- return SNMP_ERR_GENERR;
+ case EOCSOFTWAREUPGRADEPROCEED_UPGRADE:
+ if (INTERNAL_EOCSOFTWAREUPGRADETABLE_EOCSOFTWAREUPGRADERESULT_UPGRADING
+ != eocSoftwareUpgradeResult[current_index])
+ {
+ rowreq_ctx->data.eocSoftwareUpgradeProceed =
+ INTERNAL_EOCSOFTWAREUPGRADETABLE_EOCSOFTWAREUPGRADEPROCEED_UPGRADE;
+
+ /* convert MAC address from bin to string */
+ ret = libspid_mac_bin_to_str (
+ rowreq_ctx->data.eocSoftwareUpgradeMACAddress,
+ mac_str);
+ if (LIBSPID_SUCCESS != ret)
+ {
+ snmp_log (LOG_ERR, "libspid_mac_bin_to_str error\n");
+ eocSoftwareUpgradeResult[current_index] =
+ INTERNAL_EOCSOFTWAREUPGRADETABLE_EOCSOFTWAREUPGRADERESULT_UPGRADEFAILED;
+ /* set internal upgrade result in row request context
+ (to be updated before container reload) */
+ rowreq_ctx->data.eocSoftwareUpgradeResult =
+ INTERNAL_EOCSOFTWAREUPGRADETABLE_EOCSOFTWAREUPGRADERESULT_UPGRADEFAILED;
+ return SNMP_ERR_COMMITFAILED;
+ }
+ DEBUGMSGTL (("verbose:eocSoftwareUpgradeTable:",
+ "eocSoftwareUpgradeProceed_set",
+ "slave MAC address: |%s|\n", mac_str));
+
+ /* copy current slave filename - to be preserved in
+ case container is reloaded */
+ filename_len =
+ rowreq_ctx->data.eocSoftwareUpgradeFileName_len;
+ strncpy (filename,
+ rowreq_ctx->data.eocSoftwareUpgradeFileName,
+ filename_len);
+ filename[filename_len] = '\0';
+
+ DEBUGMSGTL (("verbose:eocSoftwareUpgradeTable:",
+ "eocSoftwareUpgradeProceed_set",
+ "slave filename: |%s|\n", filename));
+
+ /* denote update action field for current slave
+ in update.info file and set status field to running */
+ elt_buffer[0] = filename;
+ sprintf (action_string, "%d", LIBSPID_UPDATE_ACTION_UPDATE);
+ sprintf (result_string, "%d", LIBSPID_UPDATE_RUNNING);
+ sprintf (action_last_string, "%d",
+ LIBSPID_UPDATE_ACTION_UPDATE);
+ elt_buffer[1] = action_string;
+ elt_buffer[2] = result_string;
+ elt_buffer[3] = action_last_string;
+
+ /* write MAC, filename and actions to update.info file */
+ ret = libspid_config_write_line (LIBSPID_UPDATE_INFO_PATH,
+ delimiter, mac_str,
+ 4, elt_buffer);
+
+ if (LIBSPID_SUCCESS != ret)
+ {
+ snmp_log (LOG_ERR, "libspid_config_write_line error\n");
+ return SNMP_ERR_COMMITFAILED;
+ }
+
+ /* save update file to flash */
+ ret = libspid_system_save_file (LIBSPID_UPDATE_INFO_PATH);
+ if (LIBSPID_SUCCESS != ret)
+ {
+ snmp_log (LOG_ERR, "libspid_system_save_file error\n");
+ return SNMP_ERR_COMMITFAILED;
+ }
+ else
+ {
+ /* set internal upgrade status to running in result array
+ (to be preserved in case container is reloaded) */
+ eocSoftwareUpgradeResult[current_index] =
+ INTERNAL_EOCSOFTWAREUPGRADETABLE_EOCSOFTWAREUPGRADERESULT_UPGRADING;
+
+ /* set internal upgrade status to running in row request
+ context (to be updated before container reload) */
+ rowreq_ctx->data.eocSoftwareUpgradeResult =
+ INTERNAL_EOCSOFTWAREUPGRADETABLE_EOCSOFTWAREUPGRADERESULT_UPGRADING;
+ }
+ }
+ else
+ {
+
+ snmp_log (LOG_ERR, "eocSoftwareUpgradeProceed_set: Another"
+ " upgrade action already running for selected"
+ " slave!\n");
+ return SNMP_ERR_RESOURCEUNAVAILABLE;
+ }
+ break;
+
+ default:
+ snmp_log (LOG_ERR, "couldn't reverse map value %ld for "
+ "eocSoftwareUpgradeProceed\n",
+ eocSoftwareUpgradeProceed_val);
+ return SNMP_ERR_GENERR;
+ }
}
- /*
- ***---------------------------------------------***
- *** END EXAMPLE CODE ***
- ***************************************************/
+
+ /* destroy thread attributes */
+ pthread_attr_destroy (&attr);
+
+ /* destroy mutexes */
+ pthread_mutex_destroy (&mutex_reload);
+ pthread_mutex_destroy (&mutex_dl);
+
return MFD_SUCCESS;
} /* eocSoftwareUpgradeProceed_set */
@@ -1166,8 +1518,291 @@ eocSoftwareUpgradeProceed_undo( eocSoftwareUpgradeTable_rowreq_ctx *rowreq_ctx)
*/
rowreq_ctx->data.eocSoftwareUpgradeProceed = rowreq_ctx->undo->eocSoftwareUpgradeProceed;
-
+
return MFD_SUCCESS;
} /* eocSoftwareUpgradeProceed_undo */
+/* download master image from server image path */
+/* server image path must be given relative to FTP directory on server */
+int
+eocSoftwareUpgrade_server_download (char *server_path)
+{
+ char *dir = MASTER_IMG_DIR;
+ char ip[LIBSPID_IP_MAX_LEN];
+ char login[SW_UPGRADE_LOGIN_MAX_LEN];
+ char password[SW_UPGRADE_PASSWORD_MAX_LEN];
+ char port[LIBSPID_LINE_MAX_LEN];
+ char cmd[1024];
+
+ FILE *pipe;
+ char line[1024];
+
+ char *img_file;
+ char *img_dir;
+
+ int ret;
+
+ /* check input parameter */
+ if (server_path == NULL)
+ {
+ snmp_log (LOG_ERR, "error in master image transfer parameters!\n");
+ return -1;
+ }
+
+ /* get image file server IP */
+ if ((libspid_config_read_item (LIBSPID_SYSTEM_CONF_PATH,
+ LIBSPID_SYSTEM_CONF_LABEL_UPGRADE_SERVER_IP,
+ ip,
+ LIBSPID_IP_MAX_LEN)) != LIBSPID_SUCCESS)
+ {
+ snmp_log (LOG_ERR, "error getting master image file server IP!\n");
+ return -1;
+ }
+
+ /* get server login and password */
+ if ((libspid_config_read_item (
+ LIBSPID_SYSTEM_CONF_PATH,
+ LIBSPID_SYSTEM_CONF_LABEL_UPGRADE_SERVER_LOGIN,
+ login,
+ SW_UPGRADE_LOGIN_MAX_LEN)) != LIBSPID_SUCCESS)
+ {
+ snmp_log (LOG_ERR, "error getting master image file server login!\n");
+ return -1;
+
+ }
+
+ if ((libspid_config_read_item (
+ LIBSPID_SYSTEM_CONF_PATH,
+ LIBSPID_SYSTEM_CONF_LABEL_UPGRADE_SERVER_PASSWORD,
+ password,
+ SW_UPGRADE_PASSWORD_MAX_LEN)) != LIBSPID_SUCCESS)
+ {
+ snmp_log (LOG_ERR,
+ "error getting master image file server password!\n");
+ return -1;
+
+ }
+
+ /* get server port */
+ if ((libspid_config_read_item (
+ LIBSPID_SYSTEM_CONF_PATH,
+ LIBSPID_SYSTEM_CONF_LABEL_UPGRADE_SERVER_PORT,
+ port,
+ LIBSPID_LINE_MAX_LEN)) != LIBSPID_SUCCESS)
+ {
+ snmp_log (LOG_ERR, "error getting master image file server port!\n");
+ return -1;
+ }
+
+ pthread_mutex_lock (&mutex_dl);
+ dl_active = 1;
+
+ /* remove leading slashes from server path, if existing
+ (only relative paths are supported) */
+ while (*server_path == '/')
+ {
+ server_path++;
+ }
+
+ /* parse name of the image file from server path */
+ img_file = basename (strdup (server_path));
+
+ /* create string containing shell command for
+ downloading image from server */
+ sprintf (cmd, "cd %s; ftpget -u %s -p %s %s -P %s %s %s 2>&1",
+ dir, login, password, ip, port, img_file, server_path);
+ syslog (LOG_DEBUG, "initiating download of master image file: %s",
+ " from server path: %s\n", img_file, server_path);
+
+ /* create one way pipeline for image download */
+ if (NULL == (pipe = popen (cmd, "r")))
+ {
+ syslog (LOG_DEBUG, "failed download of master image file:",
+ " %s: error opening pipe\n", img_file);
+ ret = -1;
+ }
+ else
+ {
+ /* process download results */
+ /* if result is empty, check for EOF */
+ if (NULL == fgets (line, sizeof (line), pipe))
+ {
+ if (!(feof (pipe)))
+ {
+ syslog (LOG_DEBUG, "failed download of master image file:",
+ " %s: error reading pipe\n", img_file);
+ ret = -1;
+ }
+ else
+ {
+ syslog (LOG_DEBUG, "successful download of master image ",
+ "file: %s\n", img_file);
+ ret = 0;
+ }
+ }
+ else
+ {
+ /* if result is not empty, there was an error */
+ syslog (LOG_DEBUG, "failed download of master image",
+ " file: %s\n", img_file);
+ syslog (LOG_DEBUG, "error message: %s", line);
+ ret = -1;
+ }
+ }
+
+ pclose (pipe);
+ dl_active = 0;
+ pthread_mutex_unlock (&mutex_dl);
+
+ return ret;
+}
+
+/* thread for upgrading master image */
+void *
+eocSoftwareUpgrade_thread (void *arg)
+{
+
+ eocSoftwareUpgradeTable_rowreq_ctx *rowreq_ctx;
+ int ret;
+
+ netsnmp_container *container;
+
+ char mac_str[LIBSPID_MAC_STR_LEN];
+ char server_path[DEFAULT_SNMP_STRING_MAX_LENGTH];
+ int server_path_len;
+ char cmd[1024];
+
+ int current_index = 0;
+ char image_path[1024];
+
+ char *img_file;
+
+ /* extract row request context from thread argument */
+ rowreq_ctx = (eocSoftwareUpgradeTable_rowreq_ctx *) arg;
+
+ /* set internal upgrade status to running in result array
+ *(to be preserved in case container is reloaded)
+ */
+ eocSoftwareUpgradeResult[current_index] =
+ INTERNAL_EOCSOFTWAREUPGRADETABLE_EOCSOFTWAREUPGRADERESULT_UPGRADING;
+
+
+ /* set internal upgrade status to running in row request context
+ *(to be updated before container reload)
+ */
+ rowreq_ctx->data.eocSoftwareUpgradeResult =
+ INTERNAL_EOCSOFTWAREUPGRADETABLE_EOCSOFTWAREUPGRADERESULT_UPGRADING;
+
+ /* convert MAC address from bin to string */
+ ret = libspid_mac_bin_to_str (
+ rowreq_ctx->data.eocSoftwareUpgradeMACAddress, mac_str);
+ if (LIBSPID_SUCCESS != ret)
+ {
+ snmp_log (LOG_ERR, "libspid_mac_bin_to_str error\n");
+ eocSoftwareUpgradeResult[current_index] =
+ INTERNAL_EOCSOFTWAREUPGRADETABLE_EOCSOFTWAREUPGRADERESULT_UPGRADEFAILED;
+ /* set internal upgrade result in row request context
+ *(to be updated before container reload)
+ */
+ rowreq_ctx->data.eocSoftwareUpgradeResult =
+ INTERNAL_EOCSOFTWAREUPGRADETABLE_EOCSOFTWAREUPGRADERESULT_UPGRADEFAILED;
+ pthread_exit (NULL);
+ }
+
+
+ /* copy current server path from rowreq_ctx -
+ *to be preserved in case container is reloaded
+ */
+ server_path_len = rowreq_ctx->data.eocSoftwareUpgradeFileName_len;
+ strncpy (server_path,
+ rowreq_ctx->data.eocSoftwareUpgradeFileName,
+ server_path_len);
+ server_path[server_path_len] = '\0';
+
+
+ syslog (LOG_DEBUG, "attempting master upgrade...\n");
+ /* download current master file from given server path */
+ ret = eocSoftwareUpgrade_server_download (server_path);
+
+ if (ret == -1)
+ {
+ eocSoftwareUpgradeResult[current_index] =
+ INTERNAL_EOCSOFTWAREUPGRADETABLE_EOCSOFTWAREUPGRADERESULT_UPGRADEFAILED;
+ /* set internal upgrade result in row request
+ *context (to be updated before container reload)
+ */
+ rowreq_ctx->data.eocSoftwareUpgradeResult =
+ INTERNAL_EOCSOFTWAREUPGRADETABLE_EOCSOFTWAREUPGRADERESULT_UPGRADEFAILED;
+ pthread_exit (NULL);
+ }
+
+
+ /* parse name of the image file from server path */
+ img_file = basename (strdup (server_path));
+
+ /* prepare full master image path for upgrade function */
+ sprintf (image_path, "%s/%s", MASTER_IMG_DIR, img_file);
+
+ /* call image upgrade function for master */
+ syslog (LOG_DEBUG, "initiating master upgrade with image",
+ " filename: %s\n", img_file);
+ ret = libspid_eoc_upgrade_local_image (image_path);
+
+
+ /* check if table has been released - if so, reload container */
+ if (table_released)
+ {
+ pthread_mutex_lock (&mutex_reload);
+
+ container = netsnmp_container_find (
+ "eocSoftwareUpgradeTable:table_container");
+ if (NULL == container)
+ {
+ snmp_log (LOG_ERR, "error finding eocSoftwareUpgradeTable"
+ " container\n");
+ }
+ else
+ {
+ eocSoftwareUpgradeTable_container_load (container);
+ }
+ pthread_mutex_unlock (&mutex_reload);
+
+ }
+
+ if (LIBSPID_SUCCESS == ret)
+ {
+ syslog (LOG_DEBUG, "successful master upgrade!\n");
+ eocSoftwareUpgradeResult[current_index] =
+ INTERNAL_EOCSOFTWAREUPGRADETABLE_EOCSOFTWAREUPGRADERESULT_UPGRADESUCCESS;
+ /* set internal upgrade result in row request
+ *context (to be updated before container reload)
+ */
+ rowreq_ctx->data.eocSoftwareUpgradeResult =
+ INTERNAL_EOCSOFTWAREUPGRADETABLE_EOCSOFTWAREUPGRADERESULT_UPGRADESUCCESS;
+ }
+ else
+ {
+ syslog (LOG_DEBUG, "failed master upgrade!\n");
+ eocSoftwareUpgradeResult[current_index] =
+ INTERNAL_EOCSOFTWAREUPGRADETABLE_EOCSOFTWAREUPGRADERESULT_UPGRADEFAILED;
+ /* set internal upgrade result in row request
+ *context (to be updated before container reload)
+ */
+ rowreq_ctx->data.eocSoftwareUpgradeResult =
+ INTERNAL_EOCSOFTWAREUPGRADETABLE_EOCSOFTWAREUPGRADERESULT_UPGRADEFAILED;
+ }
+
+ /* remove master image file after upgrade */
+ sprintf (cmd, "rm -f %s/%s", MASTER_IMG_DIR, img_file);
+ ret = system (cmd);
+
+ if (ret == -1)
+ {
+ snmp_log (LOG_ERR, "error in removing master image file: %s\n",
+ img_file);
+ }
+
+ pthread_exit (NULL);
+}
+
/** @} */