CmsRet devCtl_setOpticalParams(unsigned char * pOpticalData) { unsigned char NvramData[NVRAM_LENGTH] = {0}; NVRAM_DATA *pNvramData; CmsRet Ret; if (CMSRET_SUCCESS == (Ret = devCtl_boardIoctl(BOARD_IOCTL_FLASH_READ, NVRAM, NvramData, NVRAM_LENGTH, 0, ""))) { //set local copy of NVRAM pNvramData = (NVRAM_DATA *)NvramData; //update local copy of NVRAM memcpy (pNvramData->OpticalParams, pOpticalData, NVRAM_OPTICAL_PARAMS_SIZE); //recalc CRC for NVRAM pNvramData->ulCheckSum=0; pNvramData->ulCheckSum = cmsCrc_getCrc32(NvramData, NVRAM_LENGTH, CRC_INITIAL_VALUE); //update NVRAM in FLASH if (CMSRET_SUCCESS != (Ret = devCtl_boardIoctl(BOARD_IOCTL_FLASH_WRITE, NVRAM, NvramData, NVRAM_LENGTH, 0, ""))) { cmsLog_error("Unable to write optical params to NVRAM\n"); } } else { cmsLog_error("Unable to read optical params in NVRAM\n"); } return Ret; }
int main(int argc, char *argv[]) { #if defined(AEI_VDSL_CUSTOMER_BELLALIANT) CmsRet ret; cmsLog_init(EID_LEDCTL); cmsLog_setLevel(DEFAULT_LOG_LEVEL); if ((ret = cmsMsg_init(EID_LEDCTL, &msgHandle)) != CMSRET_SUCCESS) { cmsLog_error("msg initialization failed, ret=%d", ret); cmsLog_cleanup(); return 0; } #endif if (argc != 3) { usage(1); } cmsLog_error("++++++++%s %s",argv[1],argv[2]); if (!cmsUtl_strcmp(argv[1], "WAN")) { processWanLed(argv[2]); } else { usage(1); } #if defined(AEI_VDSL_CUSTOMER_BELLALIANT) cmsMsg_cleanup(&msgHandle); cmsLog_cleanup(); #endif return 0; }
CmsRet oalMsg_send(SINT32 fd, const CmsMsgHeader *buf) { UINT32 totalLen; SINT32 rc; CmsRet ret=CMSRET_SUCCESS; totalLen = sizeof(CmsMsgHeader) + buf->dataLength; rc = write(fd, buf, totalLen); if (rc < 0) { if (errno == EPIPE) { /* * This could happen when smd tries to write to an app that * has exited. Don't print out a scary error message. * Just return an error code and let upper layer app handle it. */ cmsLog_debug("got EPIPE, dest app is dead"); return CMSRET_DISCONNECTED; } else { cmsLog_error("write failed, errno=%d", errno); ret = CMSRET_INTERNAL_ERROR; } } else if (rc != (SINT32) totalLen) { cmsLog_error("unexpected rc %d, expected %u", rc, totalLen); ret = CMSRET_INTERNAL_ERROR; } return ret; }
void *cmsMem_realloc(void *origBuf, UINT32 size) { void *buf; UINT32 origSize, origAllocSize, origAllocFlags; UINT32 allocSize; UINT32 *intBuf; if (origBuf == NULL) { cmsLog_error("cannot take a NULL buffer"); return NULL; } if (size == 0) { cmsMem_free(origBuf); return NULL; } allocSize = REAL_ALLOC_SIZE(size); intBuf = (UINT32 *) (((UINT32) origBuf) - CMS_MEM_HEADER_LENGTH); origAllocFlags = intBuf[0]; origSize = intBuf[1]; /* sanity check the original length */ if (intBuf[1] != (intBuf[2] ^ 0xffffffff)) { cmsLog_error("memory underflow detected, %d %d", intBuf[1], intBuf[2]); cmsAst_assert(0); return NULL; } origAllocSize = REAL_ALLOC_SIZE(origSize); if (allocSize <= origAllocSize) { /* currently, I don't shrink buffers, but could in the future. */ return origBuf; } buf = cmsMem_alloc(allocSize, origAllocFlags); if (buf != NULL) { /* got new buffer, copy orig buffer to new buffer */ memcpy(buf, origBuf, origSize); cmsMem_free(origBuf); } else { /* * We could not allocate a bigger buffer. * Return NULL but leave the original buffer untouched. */ } return buf; }
CmsRet cmsUtl_replaceEui64(const char *address1, char *address2) { struct in6_addr in6Addr1, in6Addr2; if (inet_pton(AF_INET6, address1, &in6Addr1) <= 0) { cmsLog_error("Invalid address=%s", address1); return CMSRET_INVALID_ARGUMENTS; } if (inet_pton(AF_INET6, address2, &in6Addr2) <= 0) { cmsLog_error("Invalid address=%s", address2); return CMSRET_INVALID_ARGUMENTS; } in6Addr2.s6_addr32[2] = in6Addr1.s6_addr32[2]; in6Addr2.s6_addr32[3] = in6Addr1.s6_addr32[3]; if (inet_ntop(AF_INET6, &in6Addr2, address2, BUFLEN_40) == NULL) { cmsLog_error("inet_ntop returns NULL"); return CMSRET_INTERNAL_ERROR; } return CMSRET_SUCCESS; } /* End of cmsUtl_replaceEui64() */
/** The original cfm bcmSystem() functions forks a command within a shell. * * The prctl_spawnProcess cannot handle that, so we have a small hack for * supporting that here. */ static int runCommandInShell(char *command) { int pid; pid = fork(); if (pid == -1) { cmsLog_error("fork failed!"); return -1; } if (pid == 0) { /* this is the child */ int i; char *argv[4]; /* close all of the child's other fd's */ for (i=3; i <= 50; i++) { close(i); } argv[0] = "sh"; argv[1] = "-c"; argv[2] = command; argv[3] = 0; execv("/bin/sh", argv); cmsLog_error("Should not have reached here!"); exit(127); } /* parent returns the pid */ return pid; }
CmsRet oal_Net_getGMACPortIfNameList(char **GMACPortIfNameList) { #ifdef CMS_BRCM_GMAC #ifdef DESKTOP_LINUX *GMACPortIfNameList = cmsMem_alloc(512, 0); strcpy(*GMACPortIfNameList, "eth1,eth3"); #else SINT32 skfd; struct ifreq ifr; if ((skfd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) { cmsLog_error("Error openning socket for getting the GMAC enet port list"); return CMSRET_INTERNAL_ERROR; } /* Get the name -> if_index mapping for ethswctl */ strcpy(ifr.ifr_name, "bcmsw"); if (ioctl(skfd, SIOCGIFINDEX, &ifr) < 0) { close(skfd); cmsLog_debug("bcmsw interface does not exist. Error: %d", errno); return CMSRET_INTERNAL_ERROR; } /* Allocate dynamic memory to hold max interface names (eth0,eth1,..eth10<cr>)*/ if ((*GMACPortIfNameList = cmsMem_alloc(((MAX_GMAC_ETH_PORT * (IFNAMSIZ+1)) + 2), ALLOC_ZEROIZE)) == NULL) { cmsLog_error("Fail to alloc mem in getting the GMAC enet port list"); close(skfd); return CMSRET_RESOURCE_EXCEEDED; } memset((void *) &ifr, sizeof(ifr), 0); ifr.ifr_data = *GMACPortIfNameList; if (ioctl(skfd, SIOCGGMACPORT, &ifr) < 0) { cmsLog_error("ioct error in getting the GMAC enet port list. Error: %d", errno); close(skfd); CMSMEM_FREE_BUF_AND_NULL_PTR(*GMACPortIfNameList); return CMSRET_INTERNAL_ERROR; } close(skfd); cmsLog_debug("GMACPortIfNameList=%s, strlen=%d", *GMACPortIfNameList, strlen(*GMACPortIfNameList)); #endif /* DESKTOP_LINUX */ #endif /* CMS_BRCM_GMAC */ return CMSRET_SUCCESS; }
/** Write contents of pBuf to flash starting at start_block for total_blocks. * * @return 0 on success, -1 on failure. */ int fake_setSharedBlks(int start_block, int total_blocks, char *pBuf) { int fd, rc; int sts=-1; char path[BUFLEN_1024]; CmsRet ret; cmsLog_debug("setting block %d through %d, buf %p", start_block, start_block+total_blocks, pBuf); if (start_block != 0) { cmsLog_error("cannot handle non-zero start block yet."); return sts; } if (total_blocks > FAKE_NUM_PSP_FLASH_BLOCKS) { cmsLog_error("requested more blocks than PSP flash blocks, not handled."); return sts; } /* form path to the flash file */ if ((ret = cmsUtl_getBaseDir(path, sizeof(path))) != CMSRET_SUCCESS) { cmsLog_error("getBaseDir failed, abort func"); return sts; } else { UINT32 offset; offset = strlen(path); snprintf(&(path[offset]), sizeof(path)-offset, "/%s", FAKE_FLASH_PSP_FILENAME); } cmsLog_debug("opening fake flash file at %s", path); if ((fd = open(path, O_RDWR)) < 0) { cmsLog_error("Could not open %s", path); return sts; } rc = write(fd, pBuf, total_blocks * FAKE_FLASH_BLOCK_SIZE); if (rc != total_blocks * FAKE_FLASH_BLOCK_SIZE) { cmsLog_error("bad write, got %d expected %d", rc, total_blocks * FAKE_FLASH_BLOCK_SIZE); } else { cmsLog_debug("%d blocks (%d bytes) written", total_blocks, total_blocks * FAKE_FLASH_BLOCK_SIZE); sts = 0; } close(fd); return sts; }
CmsRet cmsUtl_atmVpiVciStrToNum(const char *vpiVciStr, SINT32 *vpi, SINT32 *vci) { char *pSlash; char vpiStr[BUFLEN_256]; char vciStr[BUFLEN_256]; char *prefix; *vpi = *vci = -1; if (vpiVciStr == NULL) { cmsLog_error("vpiVciStr is NULL"); return CMSRET_INVALID_ARGUMENTS; } strncpy(vpiStr, vpiVciStr, sizeof(vpiStr)); if (strstr(vpiStr, DSL_LINK_DESTINATION_PREFIX_SVC)) { cmsLog_error("DesitinationAddress string %s with %s is not supported yet.", vpiStr, DSL_LINK_DESTINATION_PREFIX_SVC); return CMSRET_INVALID_PARAM_VALUE; } if ((prefix = strstr(vpiStr, DSL_LINK_DESTINATION_PREFIX_PVC)) == NULL) { cmsLog_error("Invalid DesitinationAddress string %s", vpiStr); return CMSRET_INVALID_PARAM_VALUE; } /* skip the prefix */ #if 0 prefix += sizeof(DSL_LINK_DESTINATION_PREFIX_PVC); #endif prefix += strlen(DSL_LINK_DESTINATION_PREFIX_PVC); /* skip the blank if there is one */ if (*prefix == ' ') { prefix += 1; } pSlash = (char *) strchr(prefix, '/'); if (pSlash == NULL) { cmsLog_error("vpiVciStr %s is invalid", vpiVciStr); return CMSRET_INVALID_ARGUMENTS; } strncpy(vciStr, (pSlash + 1), sizeof(vciStr)); *pSlash = '\0'; *vpi = atoi(prefix); *vci = atoi(vciStr); if (cmsUtl_isValidVpiVci(*vpi, *vci) == FALSE) { return CMSRET_INVALID_PARAM_VALUE; } return CMSRET_SUCCESS; }
UBOOL8 cmsNet_isHostInSameSubnet(const char *addrHost, const char *addrPrefix) { char address[INET6_ADDRSTRLEN]; char prefix1[INET6_ADDRSTRLEN]; char prefix2[INET6_ADDRSTRLEN]; UINT32 plen = 0; CmsRet ret; *address = '\0'; *prefix1 = '\0'; *prefix2 = '\0'; if (IS_EMPTY_STRING(addrHost) && IS_EMPTY_STRING(addrPrefix)) { return TRUE; } if (addrHost == NULL || addrPrefix == NULL) { return FALSE; } if (strchr(addrHost, '/') != NULL) { cmsLog_error("Invalid host address %s", addrHost); return FALSE; } if (strchr(addrPrefix, '/') == NULL) { cmsLog_error("Invalid address prefix %s", addrPrefix); return FALSE; } if ((ret = cmsUtl_parsePrefixAddress(addrPrefix, address, &plen)) != CMSRET_SUCCESS) { cmsLog_error("cmsUtl_parsePrefixAddress returns error. ret=%d", ret); return FALSE; } if ((ret = cmsUtl_getAddrPrefix(addrHost, plen, prefix1)) != CMSRET_SUCCESS) { cmsLog_error("cmsUtl_getAddrPrefix returns error. ret=%d", ret); return FALSE; } if ((ret = cmsUtl_getAddrPrefix(address, plen, prefix2)) != CMSRET_SUCCESS) { cmsLog_error("cmsUtl_getAddrPrefix returns error. ret=%d", ret); return FALSE; } return (cmsNet_areIp6AddrEqual(prefix1, prefix2)); } /* cmsNet_isHostInSameSubnet() */
/* Encode the output value base on microsoft standard*/ char* AEI_SpeciCharEncode(char *s, int len) { int c; int n = 0; char t[4096]={0}; char *p; p=s; memset(t,0,sizeof(t)); if (s == NULL) { cmsLog_error("The transfer object is null"); return s; } while ((c = *p++)&& n < 4096) { /* Yuki: Special characters |,/()+ \are used by join characters, also need Encode them. */ if (!strchr("<>\"'%;)(&+|,/\\", c)) { t[n++] = c; } else if (n < 4096-5) { t[n++] = '&'; t[n++] = '#'; /* Yuki:| encode is | */ if(strchr("|",c)){ t[n++] = (c/100) + '0'; t[n++] = ((c%100)/10) + '0'; t[n++] = ((c%100)%10) + '0'; }else{ t[n++] = (c/10) + '0'; t[n++] = (c%10) + '0'; } t[n++] = ';'; } else { cmsLog_error("The Array size overflow Exception"); return s;; } } t[n] = '\0'; if (n <= len && n < 4096) { memset(s,0,len); strncpy(s, t, n); } else cmsLog_error("The Array size overflow Exception"); return s; }
void sendEventMessageOption121(int Len , unsigned char *option121Data) { char *buf = (char*)malloc(sizeof(CmsMsgHeader)+Len); //char buf[sizeof(CmsMsgHeader) + Len]= {0}; CmsMsgHeader *msg=(CmsMsgHeader *) buf; unsigned char *Data = (unsigned char *) (msg+1); CmsRet ret; int i; msg->type = CMS_MSG_DHCPC_OPTION121; msg->src = MAKE_SPECIFIC_EID(getpid(), EID_DHCPC); msg->dst = EID_SSK; msg->flags_event = 1; msg->dataLength = Len; //strncpy(Data , option121Data , Len); for(i=0 ; i<Len ; i++) Data[i] = option121Data[i]; if ((ret = cmsMsg_send(msgHandle, msg)) != CMSRET_SUCCESS) { cmsLog_error("could not send out DHCPC_STATUS_CHANGED, ret=%d", ret); } else { cmsLog_notice("sent out DHCPC_OPTION121 (Len=%d)", Len); } free(buf); return; }
SINT32 cmsUtl_syslogModeToNum(const char *modeStr) { SINT32 mode=1; /* * These values are hard coded in httpd/html/logconfig.html. * Any changes to these values must also be reflected in that file. */ if (!strcmp(modeStr, MDMVS_LOCAL_BUFFER)) { mode = 1; } else if (!strcmp(modeStr, MDMVS_REMOTE)) { mode = 2; } else if (!strcmp(modeStr, MDMVS_LOCAL_BUFFER_AND_REMOTE)) { mode = 3; } else { cmsLog_error("unsupported mode string %s, default to mode=%d", modeStr, mode); } /* * The data model also specifies LOCAL_FILE and LOCAL_FILE_AND_REMOTE, * but its not clear if syslogd actually supports local file mode. */ return mode; }
char * cmsUtl_numToPppAuthString(SINT32 authNum) { char *authStr = MDMVS_AUTO_AUTH; /* default to auto */ switch(authNum) { case PPP_AUTH_METHOD_AUTO: authStr = MDMVS_AUTO_AUTH; break; case PPP_AUTH_METHOD_PAP: authStr = MDMVS_PAP; break; case PPP_AUTH_METHOD_CHAP: authStr = MDMVS_CHAP; break; case PPP_AUTH_METHOD_MSCHAP: authStr = MDMVS_MS_CHAP; break; default: cmsLog_error("unsupported authNum %d, default to %s", authNum, authStr); break; } return authStr; }
SINT32 cmsNet_getIfindexByIfname(char *ifname) { int sockfd; int idx; int ifindex = -1; struct ifreq ifr; /* open socket to get INET info */ if ((sockfd = socket(PF_INET, SOCK_DGRAM, 0)) <= 0) { cmsLog_error("socket returns error. sockfd=%d", sockfd); return -1; } for (idx = 2; idx < 32; idx++) { memset(&ifr, 0, sizeof(struct ifreq)); ifr.ifr_ifindex = idx; if (ioctl(sockfd, SIOCGIFNAME, &ifr) >= 0) { if (strcmp(ifname, ifr.ifr_name) == 0) { ifindex = idx; break; } } } close(sockfd); return ifindex; } /* End of cmsNet_getIfindexByIfname() */
CmsRet prctl_terminateProcessGracefully(SINT32 pid) { cmsLog_error("Not implemented yet. (pid=%d)", pid); /* mwang_todo: just send a terminate message to the process ? */ return CMSRET_INTERNAL_ERROR; }
char * cmsUtl_numToSyslogModeString(SINT32 mode) { char *modeString = MDMVS_LOCAL_BUFFER; /* * These values are hard coded in httpd/html/logconfig.html. * Any changes to these values must also be reflected in that file. */ switch(mode) { case 1: modeString = MDMVS_LOCAL_BUFFER; break; case 2: modeString = MDMVS_REMOTE; break; case 3: modeString = MDMVS_LOCAL_BUFFER_AND_REMOTE; break; default: cmsLog_error("unsupported mode %d, default to %s", mode, modeString); break; } /* * The data model also specifies LOCAL_FILE and LOCAL_FILE_AND_REMOTE, * but its not clear if syslogd actually supports local file mode. */ return modeString; }
SINT32 cmsUtl_pppAuthToNum(const char *authStr) { SINT32 authNum = PPP_AUTH_METHOD_AUTO; /* default is auto */ if (!strcmp(authStr, MDMVS_AUTO_AUTH)) { authNum = PPP_AUTH_METHOD_AUTO; } else if (!strcmp(authStr, MDMVS_PAP)) { authNum = PPP_AUTH_METHOD_PAP; } else if (!strcmp(authStr, MDMVS_CHAP)) { authNum = PPP_AUTH_METHOD_CHAP; } else if (!strcmp(authStr, MDMVS_MS_CHAP)) { authNum = PPP_AUTH_METHOD_MSCHAP; } else { cmsLog_error("unsupported auth string %s, default to auto=%d", authStr, authNum); } return authNum; }
CmsRet cmsEid_getStringNamesFromBitMask(UINT16 bitMask, char **buf) { UINT32 i, mask; UINT32 len=1; /* for empty mask, return a buffer with an empty string. */ UINT32 idx=0; UINT32 numBits = sizeof(bitMask) * 8; const CmsEntityInfo *info; UBOOL8 firstName=TRUE; CmsRet ret = CMSRET_SUCCESS; /* first loop calculates how much space needed for string names */ for (mask=1, i=0; i < numBits; i++) { info = cmsEid_getEntityInfoByAccessBit(bitMask & mask); if (info == NULL) { if (bitMask & mask) { cmsLog_error("unrecognized bitmask 0x%x", (bitMask & mask)); ret = CMSRET_SUCCESS_UNRECOGNIZED_DATA_IGNORED; } } else { len += strlen(info->name) + 1; } mask = mask << 1; } if (((*buf) = cmsMem_alloc(len, ALLOC_ZEROIZE)) == NULL) { return CMSRET_RESOURCE_EXCEEDED; } /* this loop copies string names into buffer */ for (mask=1, i=0; i < numBits; i++) { info = cmsEid_getEntityInfoByAccessBit(bitMask & mask); if (info != NULL) { if (firstName) { idx = sprintf((*buf), "%s", info->name); firstName = FALSE; } else { idx += sprintf(&((*buf)[idx]), ",%s", info->name); } } mask = mask << 1; } cmsAst_assert(idx < len); return ret; }
UBOOL8 cmsNet_isAddressOnLanSide(const char *ipAddr) { UBOOL8 onLanSide = FALSE; /* determine the address family of ipAddr */ if ((ipAddr != NULL) && (strchr(ipAddr, ':') == NULL)) { /* ipv4 address */ struct in_addr clntAddr, inAddr, inMask; #ifdef DESKTOP_LINUX /* * Many desktop linux tests occur on loopback interface. Consider that * as LAN side. */ if (!strcmp(ipAddr, "127.0.0.1")) { return TRUE; } #endif clntAddr.s_addr = inet_addr(ipAddr); oal_getLanInfo("br0", &inAddr, &inMask); /* check ip address of support user to see it is in LAN or not */ if ( (clntAddr.s_addr & inMask.s_addr) == (inAddr.s_addr & inMask.s_addr) ) onLanSide = TRUE; else { /* check ip address of support user to see if it is from secondary LAN */ if (oal_isInterfaceUp("br0:0")) { oal_getLanInfo("br0:0", &inAddr, &inMask); if ( (clntAddr.s_addr & inMask.s_addr) == (inAddr.s_addr & inMask.s_addr) ) onLanSide = TRUE; } /* This function will not work for ppp ip extension. See dal_auth.c for detail */ } } #ifdef DMP_X_BROADCOM_COM_IPV6_1 /* aka SUPPORT_IPV6 */ else { /* ipv6 address */ char lanAddr6[CMS_IPADDR_LENGTH]; if (oal_getLanAddr6("br0", lanAddr6) != CMSRET_SUCCESS) { cmsLog_error("oal_getLanAddr6 returns error."); } else { /* see if the client addr is in the same subnet as br0. */ onLanSide = cmsNet_isHostInSameSubnet(ipAddr, lanAddr6); } } #endif return onLanSide; } /* End of cmsNet_isAddressOnLanSide() */
CmsRet cmsUtl_parsePrefixAddress(const char *prefixAddr, char *address, UINT32 *plen) { CmsRet ret = CMSRET_SUCCESS; char *tmpBuf; char *separator; UINT32 len; if (prefixAddr == NULL || address == NULL || plen == NULL) { return CMSRET_INVALID_ARGUMENTS; } cmsLog_debug("prefixAddr=%s", prefixAddr); *address = '\0'; *plen = 128; len = strlen(prefixAddr); if ((tmpBuf = cmsMem_alloc(len+1, 0)) == NULL) { cmsLog_error("alloc of %d bytes failed", len); ret = CMSRET_INTERNAL_ERROR; } else { sprintf(tmpBuf, "%s", prefixAddr); separator = strchr(tmpBuf, '/'); if (separator != NULL) { /* break the string into two strings */ *separator = 0; separator++; while ((isspace(*separator)) && (*separator != 0)) { /* skip white space after comma */ separator++; } *plen = atoi(separator); cmsLog_debug("plen=%d", *plen); } cmsLog_debug("address=%s", tmpBuf); if (strlen(tmpBuf) < BUFLEN_40 && *plen <= 128) { strcpy(address, tmpBuf); } else { ret = CMSRET_INVALID_ARGUMENTS; } cmsMem_free(tmpBuf); } return ret; } /* End of cmsUtl_parsePrefixAddress() */
CmsRet oal_signalProcess(SINT32 pid, SINT32 sig) { SINT32 rc; if (pid <= 0) { cmsLog_error("bad pid %d", pid); return CMSRET_INVALID_ARGUMENTS; } if ((rc = kill(pid, sig)) < 0) { cmsLog_error("invalid signal(%d) or pid(%d)", sig, pid); return CMSRET_INVALID_ARGUMENTS; } return CMSRET_SUCCESS; }
int AEI_removeFile(char *filename) { int ret = 0; if (remove(filename) != 0) { cmsLog_error("Could not remove %s file=%d", filename); ret = -1; } return ret; }
CmsRet cmsUtl_macStrToNum(const char *macStr, UINT8 *macNum) { char *pToken = NULL; char *pLast = NULL; char *buf; SINT32 i; if (macNum == NULL || macStr == NULL) { cmsLog_error("Invalid macNum/macStr %p/%p", macNum, macStr); return CMSRET_INVALID_ARGUMENTS; } if (cmsUtl_isValidMacAddress(macStr) == FALSE) { return CMSRET_INVALID_PARAM_VALUE; } if ((buf = (char *) cmsMem_alloc(MAC_STR_LEN+1, ALLOC_ZEROIZE)) == NULL) { cmsLog_error("alloc of %d bytes failed", MAC_STR_LEN+1); return CMSRET_RESOURCE_EXCEEDED; } /* need to copy since strtok_r updates string */ strcpy(buf, macStr); /* Mac address has the following format * xx:xx:xx:xx:xx:xx where x is hex number */ pToken = strtok_r(buf, ":", &pLast); macNum[0] = (UINT8) strtol(pToken, (char **)NULL, 16); for (i = 1; i < MAC_ADDR_LEN; i++) { pToken = strtok_r(NULL, ":", &pLast); macNum[i] = (UINT8) strtol(pToken, (char **)NULL, 16); } cmsMem_free(buf); return CMSRET_SUCCESS; }
UBOOL8 cmsNet_areIp6AddrEqual(const char *ip6Addr1, const char *ip6Addr2) { char address1[CMS_IPADDR_LENGTH]; char address2[CMS_IPADDR_LENGTH]; UINT32 plen1 = 0; UINT32 plen2 = 0; struct in6_addr in6Addr1, in6Addr2; CmsRet ret; if (IS_EMPTY_STRING(ip6Addr1) && IS_EMPTY_STRING(ip6Addr2)) { return TRUE; } if (ip6Addr1 == NULL || ip6Addr2 == NULL) { return FALSE; } if ((ret = cmsUtl_parsePrefixAddress(ip6Addr1, address1, &plen1)) != CMSRET_SUCCESS) { cmsLog_error("cmsUtl_parsePrefixAddress returns error. ret=%d", ret); return FALSE; } if ((ret = cmsUtl_parsePrefixAddress(ip6Addr2, address2, &plen2)) != CMSRET_SUCCESS) { cmsLog_error("cmsUtl_parsePrefixAddress returns error. ret=%d", ret); return FALSE; } if (inet_pton(AF_INET6, address1, &in6Addr1) <= 0) { cmsLog_error("Invalid address1=%s", address1); return FALSE; } if (inet_pton(AF_INET6, address2, &in6Addr2) <= 0) { cmsLog_error("Invalid address2=%s", address2); return FALSE; } return ((memcmp(&in6Addr1, &in6Addr2, sizeof(struct in6_addr)) == 0) && (plen1 == plen2)); } /* cmsNet_areIp6AddrEqual() */
SINT32 fake_flashWrite(const char *filename, UINT8 *buf, UINT32 bufLen) { char basedir[BUFLEN_1024]={0}; SINT32 fd, rc, basedirLen; CmsRet ret; if ((ret = cmsUtl_getBaseDir(basedir, sizeof(basedir))) != CMSRET_SUCCESS) { cmsLog_error("getBasedir failed, ret=%d", ret); return ret; } basedirLen = strlen(basedir); rc = snprintf(&(basedir[basedirLen]), sizeof(basedir) - basedirLen, "/%s", filename); if (rc >= ((SINT32) sizeof(basedir)) - basedirLen) { cmsLog_error("basedir var not long enough to hold entire path"); return CMSRET_RESOURCE_EXCEEDED; } fd = open(basedir, O_RDWR|O_CREAT|O_TRUNC, 0666); if (fd < 0) { cmsLog_error("Could not open %s, errno=%d", basedir, errno); return CMSRET_INTERNAL_ERROR; } rc = write(fd, buf, bufLen); if (rc != (SINT32) bufLen) { cmsLog_error("write failed, expected %u got %d", bufLen, rc); ret = CMSRET_INTERNAL_ERROR; } else { cmsLog_debug("wrote buf len=%u to %s", bufLen, basedir); ret = CMSRET_SUCCESS; } close(fd); return ret; }
UBOOL8 cmsUtl_isValidIpAddress(SINT32 af, const char* address) { #ifdef DMP_X_BROADCOM_COM_IPV6_1 /* aka SUPPORT_IPV6 */ if (af == AF_INET6) { struct in6_addr in6Addr; UINT32 plen; char addr[BUFLEN_40]; if (cmsUtl_parsePrefixAddress(address, addr, &plen) != CMSRET_SUCCESS) { cmsLog_error("Invalid ipv6 address=%s", address); return FALSE; } if (inet_pton(AF_INET6, addr, &in6Addr) <= 0) { cmsLog_error("Invalid ipv6 address=%s", address); return FALSE; } if ( in6Addr.s6_addr32[0] == 0 && in6Addr.s6_addr32[1] == 0 && in6Addr.s6_addr32[2] == 0 && (in6Addr.s6_addr32[3] == 0 || in6Addr.s6_addr32[3] == 1)) { cmsLog_error("Unspecified or loopback ipv6 address=%s", address); return FALSE; } return TRUE; } else #endif { if (af == AF_INET) { return cmsUtl_isValidIpv4Address(address); } else { return FALSE; } } } /* End of cmsUtl_isValidIpAddress() */
UBOOL8 cmsUtl_isValidVpiVci(SINT32 vpi, SINT32 vci) { if (vpi >= VPI_MIN && vpi <= VPI_MAX && vci >= VCI_MIN && vci <= VCI_MAX) { return TRUE; } cmsLog_error("invalid vpi/vci %d/%d", vpi, vci); return FALSE; }
CmsRet cmsUtl_prefixMacToAddress(const char *prefix, UINT8 *mac, char *addr) { struct in6_addr in6_addr; SINT32 i; cmsLog_debug("prefix<%s>", prefix); if (inet_pton(AF_INET6, prefix, &in6_addr) <= 0) { cmsLog_error("inet_pton returns error"); return CMSRET_INVALID_ARGUMENTS; } for ( i = 8; i <= 15; i++ ) { if (in6_addr.s6_addr[i] != 0) { cmsLog_error("prefix is not 0 at 64 LSB"); return CMSRET_INVALID_ARGUMENTS; }; }; /* create EUI-64 from MAC-48 */ in6_addr.s6_addr[ 8] = mac[0] ^ 0x02; in6_addr.s6_addr[ 9] = mac[1]; in6_addr.s6_addr[10] = mac[2]; in6_addr.s6_addr[11] = 0xff; in6_addr.s6_addr[12] = 0xfe; in6_addr.s6_addr[13] = mac[3]; in6_addr.s6_addr[14] = mac[4]; in6_addr.s6_addr[15] = mac[5]; if (inet_ntop(AF_INET6, &in6_addr, addr, CMS_IPADDR_LENGTH) == NULL) { cmsLog_error("inet_ntop returns error"); return CMSRET_INTERNAL_ERROR; } cmsLog_debug("addr<%s>", addr); return CMSRET_SUCCESS; }
UBOOL8 cmsNet_areIp6DnsEqual(const char *dnsServers1, const char *dnsServers2) { char dnsPri1[CMS_IPADDR_LENGTH]; char dnsSec1[CMS_IPADDR_LENGTH]; char dnsPri2[CMS_IPADDR_LENGTH]; char dnsSec2[CMS_IPADDR_LENGTH]; CmsRet ret; *dnsPri1 = '\0'; *dnsSec1 = '\0'; *dnsPri2 = '\0'; *dnsSec2 = '\0'; if (IS_EMPTY_STRING(dnsServers1) && IS_EMPTY_STRING(dnsServers2)) { return TRUE; } if (dnsServers1 == NULL || dnsServers2 == NULL) { return FALSE; } if ((ret = cmsUtl_parseDNS(dnsServers1, dnsPri1, dnsSec1, FALSE)) != CMSRET_SUCCESS) { cmsLog_error("cmsUtl_parseDNS returns error. ret=%d", ret); return FALSE; } if ((ret = cmsUtl_parseDNS(dnsServers2, dnsPri2, dnsSec2, FALSE)) != CMSRET_SUCCESS) { cmsLog_error("cmsUtl_parseDNS returns error. ret=%d", ret); return FALSE; } if (!cmsNet_areIp6AddrEqual(dnsPri1, dnsPri2) || !cmsNet_areIp6AddrEqual(dnsSec2, dnsSec2)) { return FALSE; } return TRUE; } /* cmsNet_areIp6DnsEqual() */