⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 intprismdownload.c

📁 vworks 下wlan的实现代码
💻 C
📖 第 1 页 / 共 5 页
字号:
/* intPrismDownload.c - Routines for downloading Firmware onto wlan cards *//* Copyright 2001-2003 Wind River Systems, Inc. *//*modification history --------------------01q,09may03,rb  Removed warnings caused by IPv6 integration01p,22apr03,ss  update to use intPrismTertAp.h01o,06may02,cjl  Adding LOCAL to match prototypes01n,03may02,rb  Updated comments as per doc review01m,24apr02,ss  free secondary buffer after download01l,08apr02,ss  Updated to use pWlanDev and WLAN_BASE_ADDR01k,04apr02,dxb  Added Prism 3 support.01j,18mar02,ss  Check for card type, then use the appropriate PDA addr for                 intPrismPdaRead01i,13mar02,ss  Refgen comment update01h,26feb02,ss  Fixed bug: check for NULL before dereferencing in                 intPrismLoadImageBuild01g,11feb02,ss  Added support for secondary f/w download01f,05feb02,dxb  Updated to include changes to wlanEnd.h01e,17jan02,ss  Added routines for getting ptr to PDA records and Info records01d,16jan02,ss  Fixed bug in intPrismPlugRecordsWrite (ptr. incremented too far)01c,10jan02,ss  Updated comments01b,21dec01,ss  Add error check in debug show routines01a,19dec01,ss  Created*//*DESCRIPTIONThis module provides routines for downloading Firmware to Intersil Prism based wlan cards.  *//* these includes are required only for intPrismSecondaryFileDownload and    intPrismSecondaryFtpDownload */#include <vxWorks.h>#include <ioLib.h> #include <stat.h>#include <string.h>#include <ftpLib.h> /* includes */#include "wrn/wlan/wlanEnd.h"#include "wrn/wlan/intPrismHw.h"#include "wrn/wlan/intPrismTertAp.h"#include "wrn/wlan/intPrismDownload.h"/**************************************************************************** * Global variables ***************************************************************************/INT32 wlanDlDebug = DEBUG_ERROR; /* DEBUG level for this module  *//**************************************************************************** * Local variables ***************************************************************************/LOCAL DATA_BLOCK * pDataBlocks; /* Blocks of data for download to card */LOCAL UINT32 numDataBlocks = 0; /* Number of Data Blocks */LOCAL DATA_RECORD * pDataRecords; /* Data records parsed from firmware */LOCAL UINT32 numDataRecords = 0;  /* Number of Data Records */LOCAL PLUG_RECORD * pPlugRecords; /* Plug records parsed from firmware */LOCAL UINT32 numPlugRecords = 0;  /* Number of Plug Records */LOCAL INFO_RECORD * pInfoRecords; /* Info records parsed from firmware */LOCAL UINT32 numInfoRecords = 0;  /* Number of Info Records */LOCAL CRC_RECORD * pCrcRecords; /* CRC records parsed from firmware */LOCAL UINT32 numCrcRecords = 0; /* Number of CRC Records */LOCAL PDA_RECORD * pPdaRecords; /* Production Data Area Records read from card */LOCAL UINT32 numPdaRecords = 0; /* Number of PDA Records */ /* Addr to start a RAM d/l at (parsed from tertiary F/W) */LOCAL UINT32 ramDownloadAddr = 0;/*************************************************************************** * DEFINES **************************************************************************//* (generous) Max line length (num of char's) of a S record found in F/W file */#define MAX_SRECORD_LEN 264 /* The value the Primary F/W expects the Secondary to have for the CRC-16   calculation. A true CRC calculation may be required by future releases of   Primary firmware */#define CRC_EXPECTED_VALUE 0xC0DE/* Max num char's for the filename string in a Hex Array F/W format */#define MAX_LEN_FW_FILENAME 80#define MAX_BUFF_SIZE 200000 /* max num of bytes in a Secondary file - value is                                 used by intPrismSecondaryFtpDownload *//*************************************************************************** * Local Function declarations **************************************************************************/LOCAL STATUS intPrismSRecordsParse(char *, UINT32);LOCAL BOOL intPrismIsFwCompatible(void);LOCAL BOOL intPrismChecksumVerified(UINT8, char *);LOCAL STATUS intPrismCrcCalculate(void);LOCAL BOOL intPrismAsciiToInt(UINT8, UINT32 *);LOCAL STATUS intPrismPlugRecordAdd(UINT32, UINT32, UINT32);LOCAL STATUS intPrismCrcRecordAdd(UINT32, UINT32, UINT32);LOCAL STATUS intPrismInfoRecordAdd(UINT16, UINT16, UINT16 *);LOCAL STATUS intPrismDataRecordAdd(UINT32, UINT32, UINT16 *);LOCAL void intPrismPlugRecordsFree(void);LOCAL void intPrismDataRecordsFree(void);LOCAL void intPrismInfoRecordsFree(void);LOCAL void intPrismCrcRecordsFree(void);LOCAL void intPrismPdaRecordsFree(void);LOCAL void intPrismDataBlocksFree(void);LOCAL STATUS intPrismLoadImageBuild();LOCAL STATUS intPrismLoadImagePlug(void);LOCAL STATUS intPrismLoadImageWrite(WLAN_DEV *);/* these routines were LOCAL, but were made global for sake of intPrismSym.c LOCAL STATUS intPrismPdaRecordAdd(UINT32, UINT32, UINT16 *);LOCAL STATUS intPrismPdaRead(WLAN_DEV *, UINT32);*//****************************************************************************** intPrismSecondaryFileDownload - Initiate a Secondary firmware file download** This routine is a sample wrapper for intPrismSecondaryDownload.** A Secondary firmware file is loaded off the local filesystem and used as the* source for a firmware download on an Intersil Prism based card.  If the user* does not wish to actually write the firware to the card flash, but instead * wants to examine the data that would be written (with intPrismDumpLoadImage),* the param doDownload should be set to FALSE (0).** RETURNS: OK if the download was successful, else ERROR* ERRNO: N/A*/ STATUS intPrismSecondaryFileDownload    (    char * filename, /* the firmware filename to be loaded */    char * devName, /* wlan device name */    int devNum, /* wlan device number */    BOOL doDownload /* TRUE to do a download, FALSE to fake the download */    )     {    int fd;    struct stat fileStat;        char * pBuffer = NULL;        WLAN_DEV * pWlanDev = NULL;            /* open the file */        fd = open(filename, O_RDONLY, 0444);    if (fd == ERROR)         {        printf("intPrismSecondaryFileDownload: Error - could"               " not open file %s\n", filename);        return ERROR;        }        if (fstat(fd, &fileStat) == ERROR)         {        printf("intPrismSecondaryFileDownload: Error - "               "getting filestat info\n");        close(fd);                return ERROR;        }        /* read the file contents into a buffer */            pBuffer = (char *) malloc(fileStat.st_size);                if (pBuffer == NULL)         {        printf("intPrismSecondaryFileDownload: Error - could not malloc "               "%i bytes\n", (int) fileStat.st_size);        close(fd);        return ERROR;        }        if (read(fd, pBuffer, fileStat.st_size) != (int) fileStat.st_size)         {        printf("intPrismSecondaryFileDownload: Error - did not"               " read entire file\n");        close(fd);        free(pBuffer);        return ERROR;        }            close(fd);    /* make sure it's an Intersil card */    pWlanDev = (WLAN_DEV *) endFindByName(devName, devNum);    if ( (pWlanDev == NULL) ||          ( (((WLAN_DEV *) pWlanDev)->cardType != WLAN_CARDTYPE_INTERSIL_2) &&           (((WLAN_DEV *) pWlanDev)->cardType != WLAN_CARDTYPE_INTERSIL_2_5) &&           (((WLAN_DEV *) pWlanDev)->cardType != WLAN_CARDTYPE_INTERSIL_3) ))        {        printf("intPrismSecondaryFileDownload: Error - %s%i is not a valid "               "Intersil/Prism based wlan interface\n", devName, devNum);                if (pBuffer != NULL)             free(pBuffer);        return ERROR;        }            if (intPrismSecondaryDownload(pWlanDev, pBuffer, fileStat.st_size,                                   doDownload)        == ERROR)         {        printf("intPrismSecondaryFileDownload: Error - download "               "failed\n");        }    else         {        printf("intPrismSecondaryFileDownload: successfully downloaded %s "               "to card\n", filename);        }        if (pBuffer != NULL)        free(pBuffer);    return OK;    }/******************************************************************************* intPrismSecondaryFtpDownload - Initiate a Secondary firmware (ftp)file download** This routine is a sample wrapper for intPrismSecondaryDownload.** A Secondary firmware file is loaded off an ftp server and used as the* source for a firmware download on an Intersil Prism based card.  If the user* does not wish to actually write the firmware to card flash, but instead wants* to examine the data that would be written (with intPrismDumpLoadImage), * the param doDownload should be set to FALSE (0).** RETURNS: OK if the download was successful, else ERROR* ERRNO: N/A*/ STATUS intPrismSecondaryFtpDownload    (    char * host, /* ip addr of host FTP server */    char * user, /* username for access to FTP server */    char * pass, /* password for access to FTP server */    char * filename, /* the firmware filename to be loaded */    char * devName, /* wlan device name */    int devNum, /* wlan device number */    BOOL doDownload /* TRUE to do a download, FALSE to fake the download */    )     {    char * pBuffer;    char * pTmpBuffer;    int ctrlSock;    int dataSock;    int nBytes;    UINT32 bufferSize = 0;    WLAN_DEV * pWlanDev;        /* create an empty buffer */    pBuffer = (char *) malloc(MAX_BUFF_SIZE);    pTmpBuffer = pBuffer;        if (pBuffer == NULL)         {        printf("intPrismSecondaryFtpDownload: Error - could not allocate buffer"               " of size %i bytes\n", MAX_BUFF_SIZE);        return ERROR;        }        /* open the FTP connection */        /* NOTE: directory is assumed to be current ("") for FTP server */    if (ftpXfer (host, user, pass, "",                 "RETR %s", "", filename,                 &ctrlSock, &dataSock) == ERROR)        {        printf("intPrismSecondaryFtpDownload: Error - could not perform ftp "               " transfer\n");                if (pTmpBuffer != NULL)             free(pTmpBuffer);                return (ERROR);        }            /* read the file into a buffer */    while ((nBytes = read(dataSock, pBuffer, 512)) > 0)         {        bufferSize += nBytes;        pBuffer = pBuffer + nBytes;        }        if (bufferSize > MAX_BUFF_SIZE)         {        printf("intPrismSecondaryFtpDownload: Error - buffer for secondary"               " F/W (MAX_BUFF_SIZE) is too small at %i bytes\n", MAX_BUFF_SIZE);                if (pTmpBuffer != NULL)            free(pTmpBuffer);        return ERROR;        }        /* close the FTP connection */    close(dataSock);        if (ftpReplyGet (ctrlSock, TRUE) != FTP_COMPLETE)         {        printf("intPrismSecondaryFtpDownload - Error: closing FTP connection\n");        if (pTmpBuffer)            free(pTmpBuffer);        return ERROR;        }        if (ftpCommand (ctrlSock, "QUIT", 0, 0, 0, 0, 0, 0) != FTP_COMPLETE)        {        printf("intPrismSecondaryFtpDownload: Error - closing FTP connection\n");        if (pTmpBuffer != NULL)            free(pTmpBuffer);        return ERROR;        }        close(ctrlSock);    /* make sure it's an Intersil card */    pWlanDev = (WLAN_DEV *) endFindByName(devName, devNum);    if ( (pWlanDev == NULL) ||          ( (((WLAN_DEV *) pWlanDev)->cardType != WLAN_CARDTYPE_INTERSIL_2) &&           (((WLAN_DEV *) pWlanDev)->cardType != WLAN_CARDTYPE_INTERSIL_2_5) &&           (((WLAN_DEV *) pWlanDev)->cardType != WLAN_CARDTYPE_INTERSIL_3) ))        {        printf("intPrismSecondaryFtpDownload: Error - %s%i is not a valid "               "Intersil/Prism based wlan interface\n", devName, devNum);                if (pTmpBuffer != NULL)            free(pTmpBuffer);        return ERROR;        }            if (intPrismSecondaryDownload(pWlanDev, pTmpBuffer, bufferSize, doDownload)        == ERROR)         {        printf("intPrismSecondaryFtpDownload: Error - download "               "failed\n");                }    else         {        printf("intPrismSecondaryFtpDownload: successfully downloaded %s "               "to card\n", filename);        }        /* free the memory associated with the secondary firmware */    if (pTmpBuffer != NULL)         {        free(pTmpBuffer);        }        return OK;    }/****************************************************************************** intPrismSecondaryDownload - Download Secondary Firmware to a wlan card** Updates the Secondary firmware on Intersil Prism based cards.  The firmware * is expected in S Record format and is supplied by Intersil or the card* manufacturer.  This routine has been tested thoroughly with firmware files* S10008C2.hex, S10008C3.hex, SF010305.hex and SF010402.hex and the * corresponding compatible Prism based LinkSys cards.  However, be* careful when using this routine - a failed FLASH download (due to power loss* or bad firmware) can render your WLAN card useless.  The entire download * process should take less than a minute.** RETURNS: OK if the operation completed successfully, else ERROR*/ STATUS intPrismSecondaryDownload    (    WLAN_DEV * pWlanDev,/* device control structure */    char * pBuffer, /* buffer of char's that constitues the Secondary F/W */    UINT32 numBytes, /* num of bytes in the Secondary F/W char buffer */    BOOL doDownload /* TRUE to really perform a flash write, FALSE to do                       all download steps except actually writing to card */        )    {    LTV_RECORD ltv;    UINT16 dlMaxLoadTime = 0;    UINT16 dlBufferPage = 0;    UINT16 dlBufferOffset = 0;    UINT16 dlBufferLength = 0;    UINT32 i;    UINT32 destAddr;    UINT32 pdaAddr = 0;        UINT32 numBytesToWrite;    UINT32 blockWordIndex;    DATA_BLOCK * pDataBlockIndex;    if (pBuffer == NULL)         {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -