Пример #1
0
static int read_mac_addr_from_file(const char *p_mac_file, char *mac_addr)
{
        mm_segment_t        oldfs;
        struct file     *filp;
        struct inode        *inode = NULL;
        int         length;
        unsigned char soft_mac_tmp_buf[ATH_SOFT_MAC_TMP_BUF_LEN];
        /* open file */
        oldfs = get_fs();
        set_fs(KERNEL_DS);
        filp = filp_open(p_mac_file, O_RDONLY, S_IRUSR);

      
        printk("%s try to open file %s\n", __FUNCTION__, p_mac_file);

        if (IS_ERR(filp)) {
            printk("%s: file %s filp_open error\n", __FUNCTION__, p_mac_file);
            set_fs(oldfs);
        return -1;
        }

        if (!filp->f_op) {
            printk("%s: File Operation Method Error\n", __FUNCTION__);
            filp_close(filp, NULL);
            set_fs(oldfs);
        return -1;
        }

#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
        inode = filp->f_path.dentry->d_inode;
#else
        inode = filp->f_dentry->d_inode;
#endif
        if (!inode) {
            printk("%s: Get inode from filp failed\n", __FUNCTION__);
            filp_close(filp, NULL);
            set_fs(oldfs);
        return -1;
        }

    printk("%s file offset opsition: %xh\n", __FUNCTION__, (unsigned)filp->f_pos);

        length = filp->f_op->read(filp, soft_mac_tmp_buf, ATH_SOFT_MAC_TMP_BUF_LEN, &filp->f_pos);
        soft_mac_tmp_buf[length] = '\0'; /* ensure that it is NULL terminated */

        /* read data out successfully */
        filp_close(filp, NULL);
        set_fs(oldfs);

        /* convert mac address */
        if (!wmic_ether_aton(soft_mac_tmp_buf, length, mac_addr)) {
            printk("%s: convert mac value fail\n", __FUNCTION__);
        return -1;
        }

    return 0;
}
Пример #2
0
void _tmain(int argc, TCHAR *argv[]) {

	BYTE macAddr[6];
    TCHAR adapterName[256];
    TCHAR field[12];
    HANDLE hAdapter = NULL;
    DWORD dwReturnedBytes   = 0;
    DWORD rd;
    // Update MAC addr in buffer

	HCURSOR curr = GetCursor();
	SetCursor(LoadCursor(NULL, IDC_WAIT));

	if ((argc != 4)) {
        printUsage();
        exit(-1);
	}

    _tcsncpy(adapterName, argv[1], sizeof(adapterName)/sizeof(TCHAR));
    _tcsncpy(field, argv[2], sizeof(field)/sizeof(TCHAR));

    hAdapter = CreateFile(TEXT("DRG1:"),GENERIC_READ | GENERIC_WRITE,
                FILE_SHARE_READ | FILE_SHARE_WRITE,
                NULL,
                OPEN_EXISTING,
                FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED,
                INVALID_HANDLE_VALUE);
    if (INVALID_HANDLE_VALUE == hAdapter) {
        MessageBox(NULL,_T("Unable to open the device "),NULL,MB_OK);
        exit(-1);
    }
   
    do { 
        if ( _tcscmp( field, MAC_FIELD) == 0 ) {
	        // Parse the MAC Addr in to a BYTE array.
            if (wmic_ether_aton(argv[3], macAddr) == -1) {
                MessageBox(NULL,_T("Invalid Mac addr format"),NULL,MB_OK);
                break;
            }
      
            if (!DeviceIoControl(
                            hAdapter,
                            IOCTL_CAR6K_MACADDR_UPDATE,
                            macAddr, 
                            6,
                            NULL,
                            0,
                            &dwReturnedBytes,
                            NULL) )
            {
                MessageBox(NULL,_T("MACADDR UPDATE FAILED"),_T("eepromUpdater"),MB_OK);
            } else {
                MessageBox(NULL,_T("MACADDR UPDATE SUCCESS"),_T("eepromUpdater"),MB_OK);
            } 

        } else if ( _tcscmp( field, RD_FIELD) == 0 ) {
            if (wmic_rd_aton(argv[3], &rd) == -1) {
                MessageBox(NULL,_T("Invalid RD format"),NULL,MB_OK);
                break;
            }
            if (!DeviceIoControl(
                            hAdapter,
                            IOCTL_CAR6K_RD_UPDATE,
                            &rd, 
                            2,
                            NULL,
                            0,
                            &dwReturnedBytes,
                            NULL) )
            {
                MessageBox(NULL,_T("RD UPDATE FAILED"),_T("eepromUpdater"),MB_OK);
            } else {
                MessageBox(NULL,_T("RD UPDATE SUCCESS"),_T("eepromUpdater"),MB_OK);
            }
        } else {
            printUsage();
        }
    } while(0);

    CloseHandle (hAdapter);
    SetCursor(curr);
}