ZhiFanBriefFrame::ZhiFanBriefFrame(const PublishBriefOneEntity *entity, QWidget *parent /*= 0*/) :entity(entity) , QWidget(parent) , d_ptr(new ZhiFanBriefFramePrivate) { parseImageData(); }
void //brcm begin tftpd_receive (int peer, struct tftphdr *first_pkt, int pkt_len, int buffersize) { // brcm FILE *file=NULL; char buffer[TFTP_BLOCKSIZE_DEFAULT+4]; struct tftphdr *pkt; int block, inbytes; char *list[64]; int listcount; //brcm begin PARSE_RESULT imageType = NO_IMAGE_FORMAT; int byteRd = 0; char tag[TAG_LEN]; int tagSize = 0; int size = 0; char *curPtr = NULL; unsigned int totalAllocatedSize = 0; int socketPid = 0; int fNeedReset = FALSE; char *imagePtr = NULL; int uploadSize = 0; int i = 0; //printf("tftpd_receive, peer = %d, pkt_len = %d, buffersize=%d\n", peer, pkt_len, buffersize); pkt=(struct tftphdr *)buffer; listcount = tftpd_options (first_pkt->th_stuff, pkt_len, list ,64); /* get the size of the file (remember, chroot() supposed to point us in the right directory) */ //printf ("mode= %s, file= %s\n", list[1], list[0]); if (strcasecmp(list[1],"octet")!=0) { printf("Only support 'bin' mode. Type 'bin' at tftp client\n"); tftpd_nak(peer,EBADOP); close(peer); exit(0); } #if 0//brcm file = fopen (list[0], "w"); if (file == NULL) { tftpd_nak (peer, EACCESS); close(peer); exit(0); } #endif //brcm block=0; socketPid = bcmSocketIfPid(); // kill the app first so that when there are heavy traffic, the UDP packet will not be lost. killAllApps(socketPid, SKIP_HTTPD_APP, 0, 0); // skip kill httpd for xml config. update printf("Done removing processes\n"); fNeedReset = TRUE; do { tftpd_ack(peer,block); block++; // if duplicate pkt, (for slow ack on 38R board) discard it. for (i = 0; i < DUP_PKT_CHECK_COUNT; i++) { inbytes=tftpd_getdata(peer,block,buffer,TFTP_BLOCKSIZE_DEFAULT+4, fNeedReset); if (block == (int) (*(short*)(buffer+2))) break; } // brcm fwrite(pkt->th_msg,1,inbytes-4,file); byteRd=inbytes-4; // brcm begin if (curPtr == NULL) { if (byteRd < TFTP_BLOCKSIZE_DEFAULT) // not enough data for a valid first packet and exit { uploadSize = byteRd; break; } // The first data that is downloaded is the FILE_TAG structure. // After the entire FILE_TAG structure has been downloaded, use // the totalImageSize field to determine the size of pkt->th_msg to // allocate. if( tagSize + byteRd > TAG_LEN) size = TAG_LEN - tagSize; else size = byteRd; memcpy(tag + tagSize, pkt->th_msg, size); tagSize += size; byteRd -= size; if( tagSize == TAG_LEN ) { PFILE_TAG pTag = (PFILE_TAG) tag; if (verifyTag(pTag, 1) == UPLOAD_OK) { // if chip id mismatched. if (checkChipId(pTag->chipId, pTag->signiture_2) != 0) myExit(fNeedReset, peer); int totalImageSize = atoi(pTag->totalImageLen); // add tag len plus some pkt->th_msg for over flow during the sending... totalAllocatedSize = totalImageSize + TAG_LEN + 8; printf( "Allocating %d bytes for broadcom image.\n", totalAllocatedSize ); curPtr = (char *) malloc(totalImageSize + TAG_LEN + 8); if (curPtr == NULL) { printf("Not enough memory error."); myExit(fNeedReset, peer); } else { printf("Memory allocated\n"); imagePtr = curPtr; memcpy(curPtr, tag, TAG_LEN); curPtr += TAG_LEN; uploadSize += TAG_LEN; memcpy(curPtr, pkt->th_msg + size, byteRd); curPtr += byteRd; } } // try to allocate the memory for .w image, same as flash size + some overhead else { totalAllocatedSize = sysFlashSizeGet() + TOKEN_LEN; printf("Allocating %d bytes for flash image.\n", totalAllocatedSize); curPtr = (char *) malloc(totalAllocatedSize); if(curPtr == NULL) { printf("Not enough memory error."); myExit(fNeedReset, peer); } else { printf("Memory allocated\n"); imagePtr = curPtr; byteRd += TAG_LEN; // add back the tag size memcpy(curPtr, pkt->th_msg, byteRd); curPtr += byteRd; } } // else alloc memory for .w image } //tagSize == TAG_LEN } // if curPtr == NULL else { // not first block of data memcpy(curPtr, pkt->th_msg, byteRd); curPtr += byteRd; } uploadSize += byteRd; //printf("Current uploadSize= %d\n", uploadSize); if (uploadSize > totalAllocatedSize) // try not to over flow the pkt->th_msg { printf("Failed on data corruption during file transfer or over sized image.\n"); printf("Upload size = %d, size allowed = %d\n", uploadSize, totalAllocatedSize); myExit(fNeedReset, peer); } // brcm end } while (inbytes==(TFTP_BLOCKSIZE_DEFAULT+4)); tftpd_ack(peer,block); /* final acknowledge */ // brcm fclose(file); printf("Total size: %d\n", uploadSize); if ((imagePtr != NULL) && ((imageType = parseImageData(imagePtr, uploadSize, BUF_ALL_TYPES)) != NO_IMAGE_FORMAT)) { printf("Tftp image done.\n"); flashImage(imagePtr, imageType, uploadSize); if (imagePtr) free(imagePtr); } else printf("Tftp Image failed: Illegal image.\n"); // no reset if psi update (need httpd to process xml file) if (imageType == PSI_IMAGE_FORMAT) fNeedReset=FALSE; myExit(fNeedReset, peer); }