예제 #1
0
파일: hid-mac.c 프로젝트: hulei123/git123
struct hid_device_info  HID_API_EXPORT *hid_enumerate(unsigned short vendor_id, unsigned short product_id)
{
    struct hid_device_info *root = NULL; // return object
    struct hid_device_info *cur_dev = NULL;
    CFIndex num_devices;
    int i;
    
    setlocale(LC_ALL,"");

    /* Set up the HID Manager if it hasn't been done */
    hid_init();
    
    /* Get a list of the Devices */
    CFSetRef device_set = IOHIDManagerCopyDevices(hid_mgr);

    /* Convert the list into a C array so we can iterate easily. */ 
    num_devices = CFSetGetCount(device_set);
    IOHIDDeviceRef *device_array = calloc(num_devices, sizeof(IOHIDDeviceRef));
    CFSetGetValues(device_set, (const void **) device_array);

    /* Iterate over each device, making an entry for it. */ 
    for (i = 0; i < num_devices; i++) {
        unsigned short dev_vid;
        unsigned short dev_pid;
        #define BUF_LEN 256
        wchar_t buf[BUF_LEN];
        char cbuf[BUF_LEN];

        IOHIDDeviceRef dev = device_array[i];

        if (!dev) {
            continue;
        }
        dev_vid = get_vendor_id(dev);
        dev_pid = get_product_id(dev);

        /* Check the VID/PID against the arguments */
        if ((vendor_id == 0x0 && product_id == 0x0) ||
            (vendor_id == dev_vid && product_id == dev_pid)) {
            struct hid_device_info *tmp;
            size_t len;

                /* VID/PID match. Create the record. */
            tmp = malloc(sizeof(struct hid_device_info));
            if (cur_dev) {
                cur_dev->next = tmp;
            }
            else {
                root = tmp;
            }
            cur_dev = tmp;

            // Get the Usage Page and Usage for this device.
            cur_dev->usage_page = get_int_property(dev, CFSTR(kIOHIDPrimaryUsagePageKey));
            cur_dev->usage = get_int_property(dev, CFSTR(kIOHIDPrimaryUsageKey));

            /* Fill out the record */
            cur_dev->next = NULL;
            len = make_path(dev, cbuf, sizeof(cbuf));
            cur_dev->path = strdup(cbuf);

            /* Serial Number */
            get_serial_number(dev, buf, BUF_LEN);
            cur_dev->serial_number = dup_wcs(buf);

            /* Manufacturer and Product strings */
            get_manufacturer_string(dev, buf, BUF_LEN);
            cur_dev->manufacturer_string = dup_wcs(buf);
            get_product_string(dev, buf, BUF_LEN);
            cur_dev->product_string = dup_wcs(buf);
            
            /* VID/PID */
            cur_dev->vendor_id = dev_vid;
            cur_dev->product_id = dev_pid;

            /* Release Number */
            cur_dev->release_number = get_int_property(dev, CFSTR(kIOHIDVersionNumberKey));

            /* Interface Number (Unsupported on Mac)*/
            cur_dev->interface_number = -1;
        }
    }
    
    free(device_array);
    CFRelease(device_set);
    
    return root;
}
/* "serialno": The device serial number. */
static EFI_STATUS publish_serialno(void)
{
	char *serial = get_serial_number();
	return fastboot_publish("serialno", serial ? serial : "N/A");
}
예제 #3
0
파일: hid-mac.c 프로젝트: hulei123/git123
int HID_API_EXPORT_CALL hid_get_serial_number_string(hid_device *dev, wchar_t *string, size_t maxlen)
{
    return get_serial_number(dev->device_handle, string, maxlen);
}
예제 #4
0
/*
 * generate_and_store_mac_addr()
 * 
 * This routine is called when, upon program initialization, we discover
 * that there is no valid network settings (including MAC address) programmed
 * into flash memory at the last flash sector.  If it is not safe to use the 
 * contents of this last sector of flash, the user is prompted to
 * enter the serial number at the console.  A MAC address is then
 * generated using 0xFF followed by the last 2 bytes of the serial number 
 * appended to Altera's Vendor ID, an assigned MAC address range with the first
 * 3 bytes of 00:07:ED.  For example, if the Nios Development Board serial 
 * number is 040800017, the corresponding ethernet number generated will be
 * 00:07:ED:FF:8F:11.
 * 
 * It should be noted that this number, while unique, will likely differ from
 * the also unique (but now lost forever) MAC address programmed into the 
 * development board on the production line.
 * 
 * As we are erasing the entire flash sector, we'll re-program it with not
 * only the MAC address, but static IP, subnet, gateway, and "Use DHCP" 
 * sections. These fail-safe static settings are compatible with previous
 * Nios Ethernet designs, and allow the "factory-safe" design to behave 
 * as expected if the last flash sector is erased.
 */
error_t generate_and_store_mac_addr()
{
    error_t error = -1;
    alt_u32 ser_num = 0;
    char flash_content[32];
    alt_flash_fd* flash_handle;
    
    printf("Can't read the MAC address from your board (this probably means\n");
    printf("that your flash was erased). We will assign you a MAC address and\n");
    printf("static network settings\n\n");
    
    ser_num = get_serial_number();
  
    if (ser_num)
    {
        /* This says the image is safe */
        flash_content[0] = 0xfe;
        flash_content[1] = 0x5a;
        flash_content[2] = 0x0;
        flash_content[3] = 0x0;
        
        /* This is the Altera Vendor ID */
        flash_content[4] = 0x0;
        flash_content[5] = 0x7;
        flash_content[6] = 0xed;
        
        /* Reserverd Board identifier for erase boards */
        flash_content[7] = 0xFF;
        flash_content[8] = (ser_num & 0xff00) >> 8;
        flash_content[9] = ser_num & 0xff;
        
        /* Then comes a 16-bit "flags" field */
        flash_content[10] = 0xFF;
        flash_content[11] = 0xFF;
        
        /* Then comes the static IP address */
        flash_content[12] = IPADDR0;
        flash_content[13] = IPADDR1;
        flash_content[14] = IPADDR2;
        flash_content[15] = IPADDR3;
        
        /* Then comes the static nameserver address */
        flash_content[16] = 0xFF;
        flash_content[17] = 0xFF;
        flash_content[18] = 0xFF;
        flash_content[19] = 0xFF;
        
        /* Then comes the static subnet mask */
        flash_content[20] = MSKADDR0;
        flash_content[21] = MSKADDR1;
        flash_content[22] = MSKADDR2;
        flash_content[23] = MSKADDR3;
        
        /* Then comes the static gateway address */
        flash_content[24] = GWADDR0;
        flash_content[25] = GWADDR1;
        flash_content[26] = GWADDR2;
        flash_content[27] = GWADDR3;
        
        /* And finally whether to use DHCP - set all bits to be safe */
        flash_content[28] = 0xFF;
        flash_content[29] = 0xFF;
        flash_content[30] = 0xFF;
        flash_content[31] = 0xFF;
#if 0      
        /* Write the MAC address to flash */
        flash_handle = alt_flash_open_dev(EXT_FLASH_NAME);
        if (flash_handle)
        {
            alt_write_flash(flash_handle,
                            last_flash_sector_offset,
                            flash_content,
                            32);
            alt_flash_close_dev(flash_handle);
            error = 0;
        }
#endif
    }

    return error;    
}