/** * Set the new value. * * @param rowreq_ctx * Pointer to the users context. You should know how to * manipulate the value from this object. * @param AcInterfaceNetMask_val * A u_long containing the new value. */ int AcInterfaceNetMask_set( dot11AcInterfaceTable_rowreq_ctx *rowreq_ctx, u_long AcInterfaceNetMask_val ) { DEBUGMSGTL(("verbose:dot11AcInterfaceTable:AcInterfaceNetMask_set","called\n")); /** should never get a NULL pointer */ netsnmp_assert(NULL != rowreq_ctx); /* * TODO:461:M: |-> Set AcInterfaceNetMask value. * set AcInterfaceNetMask value in rowreq_ctx->data */ char command[128] = { 0 }; char oldmask[32] = { 0 }; char newmask[32] = { 0 }; char ip[32] = { 0 }; INET_NTOA(rowreq_ctx->data.AcInterfaceIP, ip); INET_NTOA(rowreq_ctx->data.AcInterfaceNetMask, oldmask); INET_NTOA(AcInterfaceNetMask_val,newmask); int oldMaskbit = 0, newmaskbit = 0; oldMaskbit = mask_bit(oldmask); newmaskbit = mask_bit(newmask); int ret = -1; int status = 0; //delete old info memset(command, 0, sizeof(command)); snprintf(command, sizeof(command) - 1, "sudo del_intf_ip.sh %s %s/%d 1>/dev/null 2>/dev/null", rowreq_ctx->data.AcInterfaceName, ip, oldMaskbit); status = system(command); ret = WEXITSTATUS(status); if(0 != ret) { snmp_log(LOG_WARNING, "delete old mask %s/%d fail\n", ip, oldMaskbit); return MFD_ERROR; } ret = -1; status = 0; //add new info memset(command, 0, sizeof(command)); snprintf(command, sizeof(command) - 1, "sudo /usr/bin/set_intf_ip.sh %s %s/%d > /dev/null 2>&1", rowreq_ctx->data.AcInterfaceName, ip ,newmaskbit); ret = system(command); if(ret == 0) { rowreq_ctx->data.AcInterfaceNetMask = AcInterfaceNetMask_val; return MFD_SUCCESS; } return MFD_ERROR; } /* AcInterfaceNetMask_set */
inline void tx_send_checksum(void) { int bit = 0; for(bit = 0;bit < 32;bit++){ send_manchester_symbol(mask_bit(tx_packet->checksum, bit)); } tx_packet->state = TX_WAITING_ACK; }
inline void tx_send_len(void) { int i = 0; for(i = 0;i < 32;i++){ send_manchester_symbol(mask_bit((int) tx_packet->skb->len, i)); } tx_packet->state = TX_SENDING_PACKET_DATA; }
inline void tx_send_preamble(void) { int i = 0; for(i = 0;i < 32;i++){ send_bit(mask_bit((int) VLC_PREAMBLE, i)); } tx_packet->state = TX_SENDING_SEQUENCE; }
inline void tx_send_sequence(void) { int i = 0; //Assign a sequence number tx_packet->sequence = tx_sequence_num++; for(i = 0;i < 16;i++){ send_manchester_symbol(mask_bit((int) tx_packet->sequence, i)); } tx_packet->state = TX_SENDING_PACKET_LEN; }
inline void tx_send_data(void) { int byte = 0; int bit = 0; //Reset the tx checksum prior to calculating a new one tx_reset_adler(); for(byte = 0;byte < tx_packet->skb->len;byte++){ for(bit = 0;bit < 8;bit++){ send_manchester_symbol(mask_bit(tx_packet->skb->data[byte], bit)); } //Update the rolling checksum tx_update_adler(tx_packet->skb->data[byte]); } //Store the computed checksum in the packet tx_packet->checksum = tx_B; tx_packet->state = TX_SENDING_CHECKSUM; }
inline void tx_send_ack(void) { int i = 0; for(i = 0;i < 32;i++){ send_bit(mask_bit((int) VLC_ACK, i)); } if(rx_packet->state == RX_SENDING_ACK){ rx_packet->state = PACKET_COMPLETE; /* //Check if this packet is a DUP if(rx_packet->sequence == rx_sequence_num){ rx_packet->state = PACKET_COMPLETE; rx_sequence_num++; } //If it is, set it to corrupted else rx_packet->state == PACKET_CORRUPTED; */ } }
/** * load cache data * * TODO:350:M: Implement dot11ConfigWlanTable cache load * * @param container container to which items should be inserted * * @retval MFD_SUCCESS : success. * @retval MFD_RESOURCE_UNAVAILABLE : Can't access data source * @retval MFD_ERROR : other error. * * This function is called to cache the index(es) (and data, optionally) * for the every row in the data set. * * @remark * While loading the cache, the only important thing is the indexes. * If access to your data is cheap/fast (e.g. you have a pointer to a * structure in memory), it would make sense to update the data here. * If, however, the accessing the data invovles more work (e.g. parsing * some other existing data, or peforming calculations to derive the data), * then you can limit yourself to setting the indexes and saving any * information you will need later. Then use the saved information in * dot11ConfigWlanTable_row_prep() for populating data. * * @note * If you need consistency between rows (like you want statistics * for each row to be from the same time frame), you should set all * data here. * */ int dot11ConfigWlanTable_cache_load(netsnmp_container *container) { snmp_log(LOG_DEBUG, "enter dot11ConfigWlanTable_cache_load\n"); dot11ConfigWlanTable_rowreq_ctx *rowreq_ctx; size_t count = 0; DEBUGMSGTL(("verbose:dot11ConfigWlanTable:dot11ConfigWlanTable_cache_load","called\n")); /* *************************************************** *** START EXAMPLE CODE *** ***---------------------------------------------***/ /* * open our data file. */ //filep = fopen("/etc/dummy.conf", "r"); //if(NULL == filep) { //return MFD_RESOURCE_UNAVAILABLE; //} /* ***---------------------------------------------*** *** END EXAMPLE CODE *** ***************************************************/ /* * TODO:351:M: |-> Load/update data in the dot11ConfigWlanTable container. * loop over your dot11ConfigWlanTable data, allocate a rowreq context, * set the index(es) [and data, optionally] and insert into * the container. */ infi if_head = { 0 }; interface_list_ioctl(0, &if_head); instance_parameter *para_head = NULL, *para_node = NULL; list_instance_parameter(¶_head, SNMPD_INSTANCE_MASTER); for(para_node = para_head; NULL != para_node; para_node = para_node->next) { int ret = 0; struct WLAN_INFO *wlan_info = NULL; struct WLAN_INFO *wlan_info_show = NULL; int i = 0; struct ifi *ifi_show = NULL; char bind_interface[256]= { 0 }; char wlanBindIf[255] = { 0 }; size_t wlanBindIf_len = 0; char rate[20] = { 0 }; char wlanUsrWirelessResoUseRate[255] = { 0 }; size_t wlanUsrWirelessResoUseRate_len = 0; char wlanInterfaceName[32] = { 0 }; snmp_log(LOG_DEBUG, "enter show_wlan_of_all_cmd\n"); ret = show_wlan_of_all_cmd(para_node->parameter, para_node->connection,&wlan_info); snmp_log(LOG_DEBUG, "exit show_wlan_of_all_cmd,ret=%d\n", ret); if(ret == 1) { for(wlan_info_show = wlan_info->wlan_info_list; (NULL != wlan_info_show); wlan_info_show = wlan_info_show->next) { unsigned long globalwlanID = local_to_global_ID(para_node->parameter, wlan_info_show->Wlanid, WIRELESS_MAX_NUM); /* *************************************************** *** START EXAMPLE CODE *** ***---------------------------------------------***/ /* * get a line (skip blank lines) */ //do { //if (!fgets(line, sizeof(line), filep)) { /* we're done */ //fclose(filep); //filep = NULL; //} //} while (filep && (line[0] == '\n')); /* * check for end of data */ //if(NULL == filep) //break; /* * parse line into variables */ /* ***---------------------------------------------*** *** END EXAMPLE CODE *** ***************************************************/ /* * TODO:352:M: | |-> set indexes in new dot11ConfigWlanTable rowreq context. */ rowreq_ctx = dot11ConfigWlanTable_allocate_rowreq_ctx(); if (NULL == rowreq_ctx) { snmp_log(LOG_ERR, "memory allocation failed\n"); free_inf(&if_head); Free_show_wlan_of_all_cmd(wlan_info); free_instance_parameter_list(¶_head); return MFD_RESOURCE_UNAVAILABLE; } if(MFD_SUCCESS != dot11ConfigWlanTable_indexes_set(rowreq_ctx , globalwlanID )) { snmp_log(LOG_ERR,"error setting index while loading " "dot11ConfigWlanTable cache.\n"); dot11ConfigWlanTable_release_rowreq_ctx(rowreq_ctx); continue; } /* * TODO:352:r: | |-> populate dot11ConfigWlanTable 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 wlanBindSecurity * wlanBindSecurity(1)/INTEGER/ASN_INTEGER/long(long)//l/A/W/e/r/d/h */ /* * TODO:246:r: |-> Define wlanBindSecurity mapping. * Map values between raw/native values and MIB values * * Integer based value can usually just do a direct copy. */ memcpy(&(rowreq_ctx->data.parameter), &(para_node->parameter), sizeof(dbus_parameter)); rowreq_ctx->data.local_wlanID = wlan_info_show->Wlanid; rowreq_ctx->data.wlanBindSecurity = wlan_info_show->wlanBindSecurity; /* * setup/save data for wlanBindIf * wlanBindIf(2)/DisplayString/ASN_OCTET_STR/char(char)//L/A/W/e/R/d/H */ /* * TODO:246:r: |-> Define wlanBindIf mapping. * Map values between raw/native values and MIB values * * if(MFD_SUCCESS != * wlanBindIf_map(&rowreq_ctx->data.wlanBindIf, &rowreq_ctx->data.wlanBindIf_len, * wlanBindIf, wlanBindIf_len, 0)) { * return MFD_ERROR; * } */ /* * make sure there is enough space for wlanBindIf data */ /*if ((NULL == rowreq_ctx->data.wlanBindIf) || (rowreq_ctx->data.wlanBindIf_len < (wlanBindIf_len * sizeof(rowreq_ctx->data.wlanBindIf[0])))) { snmp_log(LOG_ERR,"not enough space for value\n"); return MFD_ERROR; }*/ memset(bind_interface,0,sizeof(bind_interface)); for(i=0,ifi_show = wlan_info_show->ifi_head; ((i<wlan_info_show->bifnum)&&(NULL != ifi_show)); i++,ifi_show = ifi_show->ifi_next) { if(i == 0) { strncat(bind_interface,ifi_show->ifi_name,sizeof(bind_interface)-strlen(bind_interface)-1); } else { strncat(bind_interface,",",sizeof(bind_interface)-strlen(bind_interface)-1); strncat(bind_interface,ifi_show->ifi_name,sizeof(bind_interface)-strlen(bind_interface)-1); } } wlanBindIf_len = MIN(strlen(bind_interface),sizeof(wlanBindIf)-1); memset(wlanBindIf,0,sizeof(wlanBindIf)); memcpy(wlanBindIf,bind_interface,wlanBindIf_len); rowreq_ctx->data.wlanBindIf_len = wlanBindIf_len * sizeof(rowreq_ctx->data.wlanBindIf[0]); memcpy( rowreq_ctx->data.wlanBindIf, wlanBindIf, rowreq_ctx->data.wlanBindIf_len ); /* * setup/save data for wlanHideEssid * wlanHideEssid(3)/INTEGER/ASN_INTEGER/long(u_long)//l/A/W/E/r/d/h */ /* * TODO:246:r: |-> Define wlanHideEssid mapping. * Map values between raw/native values and MIB values * * enums usually need mapping. */ /*if(MFD_SUCCESS != wlanHideEssid_map(&rowreq_ctx->data.wlanHideEssid, wlanHideEssid )) { return MFD_ERROR; }*/ rowreq_ctx->data.wlanHideEssid = wlan_info_show->wlanHideEssid; /* * setup/save data for wlanServiceEnable * wlanServiceEnable(4)/INTEGER/ASN_INTEGER/long(u_long)//l/A/W/E/r/d/h */ /* * TODO:246:r: |-> Define wlanServiceEnable mapping. * Map values between raw/native values and MIB values * * enums usually need mapping. */ /*if(MFD_SUCCESS != wlanServiceEnable_map(&rowreq_ctx->data.wlanServiceEnable, wlanServiceEnable )) { return MFD_ERROR; }*/ if(wlan_info_show->wlanServiceEnable == 1) rowreq_ctx->data.wlanServiceEnable = 0; else rowreq_ctx->data.wlanServiceEnable = 1; /* * setup/save data for wlanMaxConnectUsr * wlanMaxConnectUsr(5)/INTEGER/ASN_INTEGER/long(long)//l/A/W/e/R/d/h */ /* * TODO:246:r: |-> Define wlanMaxConnectUsr mapping. * Map values between raw/native values and MIB values * * Integer based value can usually just do a direct copy. */ rowreq_ctx->data.wlanMaxConnectUsr = wlan_info_show->wlanMaxConnectUsr; /* * setup/save data for wlanLoadBalanceStatus * wlanLoadBalanceStatus(6)/INTEGER/ASN_INTEGER/long(u_long)//l/A/W/E/r/d/h */ /* * TODO:246:r: |-> Define wlanLoadBalanceStatus mapping. * Map values between raw/native values and MIB values * * enums usually need mapping. */ /*if(MFD_SUCCESS != wlanLoadBalanceStatus_map(&rowreq_ctx->data.wlanLoadBalanceStatus, wlanLoadBalanceStatus )) { return MFD_ERROR; }*/ if(wlan_info_show->wlanLoadBalanceFunction == 1) { if(wlan_info_show->wlanLoadBalanceStatus == 1) { rowreq_ctx->data.wlanLoadBalanceStatus = 1; } else { rowreq_ctx->data.wlanLoadBalanceStatus = 2; } } else { rowreq_ctx->data.wlanLoadBalanceStatus = 0; } /* * setup/save data for wlanLoadBalanceStatusBaseOnFlow * wlanLoadBalanceStatusBaseOnFlow(7)/INTEGER/ASN_INTEGER/long(u_long)//l/A/W/E/r/d/h */ /* * TODO:246:r: |-> Define wlanLoadBalanceStatusBaseOnFlow mapping. * Map values between raw/native values and MIB values * * enums usually need mapping. */ /*if(MFD_SUCCESS != wlanLoadBalanceStatusBaseOnFlow_map(&rowreq_ctx->data.wlanLoadBalanceStatusBaseOnFlow, wlanLoadBalanceStatusBaseOnFlow )) { return MFD_ERROR; }*/ if(wlan_info_show->wlanLoadBalanceFunction == 1) { if(wlan_info_show->wlanLoadBalanceStatus == 1) { rowreq_ctx->data.wlanLoadBalanceStatusBaseOnFlow = 0; } else { rowreq_ctx->data.wlanLoadBalanceStatusBaseOnFlow = 1; } } else { rowreq_ctx->data.wlanLoadBalanceStatusBaseOnFlow = 0; } /* * setup/save data for wlanLoadBalanceStatusBaseOnUsr * wlanLoadBalanceStatusBaseOnUsr(8)/INTEGER/ASN_INTEGER/long(u_long)//l/A/W/E/r/d/h */ /* * TODO:246:r: |-> Define wlanLoadBalanceStatusBaseOnUsr mapping. * Map values between raw/native values and MIB values * * enums usually need mapping. */ /*if(MFD_SUCCESS != wlanLoadBalanceStatusBaseOnUsr_map(&rowreq_ctx->data.wlanLoadBalanceStatusBaseOnUsr, wlanLoadBalanceStatusBaseOnUsr )) { return MFD_ERROR; }*/ if(wlan_info_show->wlanLoadBalanceFunction == 1) { if(wlan_info_show->wlanLoadBalanceStatus == 1) { rowreq_ctx->data.wlanLoadBalanceStatusBaseOnUsr = 1; } else { rowreq_ctx->data.wlanLoadBalanceStatusBaseOnUsr = 0; } } else { rowreq_ctx->data.wlanLoadBalanceStatusBaseOnUsr = 0; } /* * setup/save data for wlanLoadBalanceTrafficDiffThreshhd * wlanLoadBalanceTrafficDiffThreshhd(9)/INTEGER/ASN_INTEGER/long(long)//l/A/W/e/r/d/h */ /* * TODO:246:r: |-> Define wlanLoadBalanceTrafficDiffThreshhd mapping. * Map values between raw/native values and MIB values * * Integer based value can usually just do a direct copy. */ rowreq_ctx->data.wlanLoadBalanceTrafficDiffThreshhd = wlan_info_show->wlanLoadBalanceTrafficDiffThreshhd; /* * setup/save data for wlanLoadBalanceUsersDiffThreshhd * wlanLoadBalanceUsersDiffThreshhd(10)/INTEGER/ASN_INTEGER/long(long)//l/A/W/e/r/d/h */ /* * TODO:246:r: |-> Define wlanLoadBalanceUsersDiffThreshhd mapping. * Map values between raw/native values and MIB values * * Integer based value can usually just do a direct copy. */ rowreq_ctx->data.wlanLoadBalanceUsersDiffThreshhd = wlan_info_show->wlanLoadBalanceUsersDiffThreshhd; /* * setup/save data for wlanStaOnlineNum * wlanStaOnlineNum(11)/INTEGER/ASN_INTEGER/long(long)//l/A/w/e/r/d/h */ /* * TODO:246:r: |-> Define wlanStaOnlineNum mapping. * Map values between raw/native values and MIB values * * Integer based value can usually just do a direct copy. */ rowreq_ctx->data.wlanStaOnlineNum = wlan_info_show->wlanStaOnlineNum; /* * setup/save data for wlanUsrWirelessResoUseRate * wlanUsrWirelessResoUseRate(12)/DisplayString/ASN_OCTET_STR/char(char)//L/A/w/e/R/d/H */ /* * TODO:246:r: |-> Define wlanUsrWirelessResoUseRate mapping. * Map values between raw/native values and MIB values * * if(MFD_SUCCESS != * wlanUsrWirelessResoUseRate_map(&rowreq_ctx->data.wlanUsrWirelessResoUseRate, &rowreq_ctx->data.wlanUsrWirelessResoUseRate_len, * wlanUsrWirelessResoUseRate, wlanUsrWirelessResoUseRate_len, 0)) { * return MFD_ERROR; * } */ /* * make sure there is enough space for wlanUsrWirelessResoUseRate data */ /*if ((NULL == rowreq_ctx->data.wlanUsrWirelessResoUseRate) || (rowreq_ctx->data.wlanUsrWirelessResoUseRate_len < (wlanUsrWirelessResoUseRate_len * sizeof(rowreq_ctx->data.wlanUsrWirelessResoUseRate[0])))) { snmp_log(LOG_ERR,"not enough space for value\n"); return MFD_ERROR; }*/ memset(rate,0,sizeof(rate)); snprintf(rate,sizeof(rate)-1,"%6.5f",wlan_info_show->wlanUsrWirelessResoUseRate); strncat(rate,"%",sizeof(rate)-strlen(rate)-1); wlanUsrWirelessResoUseRate_len = MIN(strlen(rate),sizeof(wlanUsrWirelessResoUseRate)-1); memset(wlanUsrWirelessResoUseRate,0,sizeof(wlanUsrWirelessResoUseRate)); memcpy(wlanUsrWirelessResoUseRate,rate,wlanUsrWirelessResoUseRate_len); rowreq_ctx->data.wlanUsrWirelessResoUseRate_len = wlanUsrWirelessResoUseRate_len * sizeof(rowreq_ctx->data.wlanUsrWirelessResoUseRate[0]); memcpy( rowreq_ctx->data.wlanUsrWirelessResoUseRate, wlanUsrWirelessResoUseRate, rowreq_ctx->data.wlanUsrWirelessResoUseRate_len ); /* * setup/save data for wlanBindSecType * wlanBindSecType(13)/INTEGER/ASN_INTEGER/long(u_long)//l/A/w/E/r/d/h */ /* * TODO:246:r: |-> Define wlanBindSecType mapping. * Map values between raw/native values and MIB values * * enums usually need mapping. */ /*if(MFD_SUCCESS != wlanBindSecType_map(&rowreq_ctx->data.wlanBindSecType, wlanBindSecType )) { return MFD_ERROR; }*/ rowreq_ctx->data.wlanBindSecType = wlan_info_show->wlanBindSecType+1; /* * setup/save data for wlanBindEncryType * wlanBindEncryType(14)/INTEGER/ASN_INTEGER/long(u_long)//l/A/w/E/r/d/h */ /* * TODO:246:r: |-> Define wlanBindEncryType mapping. * Map values between raw/native values and MIB values * * enums usually need mapping. */ /*if(MFD_SUCCESS != wlanBindEncryType_map(&rowreq_ctx->data.wlanBindEncryType, wlanBindEncryType )) { return MFD_ERROR; }*/ rowreq_ctx->data.wlanBindEncryType = wlan_info_show->wlanBindEncryType+1; memset(wlanInterfaceName, 0, sizeof(wlanInterfaceName)); if(para_node->parameter.local_id) { snprintf(wlanInterfaceName, sizeof(wlanInterfaceName) - 1, "wlanl%d-%d-%d", para_node->parameter.slot_id, para_node->parameter.instance_id, wlan_info_show->Wlanid); } else { snprintf(wlanInterfaceName, sizeof(wlanInterfaceName) - 1, "wlan%d-%d-%d", para_node->parameter.slot_id, para_node->parameter.instance_id, wlan_info_show->Wlanid); } snmp_log(LOG_DEBUG, "wlanInterfaceName = %s\n", wlanInterfaceName); infi *if_node = NULL; for(if_node = if_head.next; NULL != if_node; if_node = if_node->next) { snmp_log(LOG_DEBUG, "if_node->if_name = %s\n", if_node->if_name); if(0 == strcmp(if_node->if_name, wlanInterfaceName)) { int mask = mask_bit(if_node->if_mask); snprintf(rowreq_ctx->data.wlanInterfaceIPAddr, sizeof(rowreq_ctx->data.wlanInterfaceIPAddr) - 1, "%s/%d", if_node->if_addr, mask); snmp_log(LOG_DEBUG, "rowreq_ctx->data.wlanInterfaceIPAddr = %s\n", rowreq_ctx->data.wlanInterfaceIPAddr); rowreq_ctx->data.wlanInterfaceIPAddr_len = strlen(rowreq_ctx->data.wlanInterfaceIPAddr); break; } } /* * insert into table container */ if(CONTAINER_INSERT(container, rowreq_ctx)) { dot11ConfigWlanTable_release_rowreq_ctx(rowreq_ctx); } ++count; } } Free_show_wlan_of_all_cmd(wlan_info); } free_instance_parameter_list(¶_head); free_inf(&if_head); /* *************************************************** *** START EXAMPLE CODE *** ***---------------------------------------------***/ //if(NULL != filep) //fclose(filep); /* ***---------------------------------------------*** *** END EXAMPLE CODE *** ***************************************************/ DEBUGMSGT(("verbose:dot11ConfigWlanTable:dot11ConfigWlanTable_cache_load", "inserted %d records\n", count)); snmp_log(LOG_DEBUG, "exit dot11ConfigWlanTable_cache_load\n"); return MFD_SUCCESS; } /* dot11ConfigWlanTable_cache_load */