-
Notifications
You must be signed in to change notification settings - Fork 0
/
iwleeprom.h
138 lines (119 loc) · 3.55 KB
/
iwleeprom.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
/*
****************************************************************************
*
* iwleeprom - EEPROM reader/writer for intel wifi cards.
* Copyright (C) 2010, Alexander "ittrium" Kalinichenko <[email protected]>
* ICQ: 152322, Skype: ittr1um
* Copyright (C) 2010, Gennady "ShultZ" Kozlov <[email protected]>
*
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
****************************************************************************
*/
#ifndef iwleeprom_h_included
#define iwleeprom_h_included
#include <stdio.h>
#include <unistd.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#if defined(__APPLE__) && defined(__MACH__)
#include <machine/byte_order.h>
#include <pci/pci.h>
#include <DirectHW/DirectHW.h>
#ifndef __bswap_16
#define __bswap_16(x) OSSwapInt16(x)
#endif
#else
#include <endian.h>
#endif
#if BYTE_ORDER == BIG_ENDIAN
#define cpu2le16(x) __bswap_16(x)
#define cpu2be16(x) x
#define le2cpu16(x) __bswap_16(x)
#define be2cpu16(x) x
#elif BYTE_ORDER == LITTLE_ENDIAN
#define cpu2le16(x) x
#define cpu2be16(x) __bswap_16(x)
#define le2cpu16(x) x
#define be2cpu16(x) __bswap_16(x)
#else
#error Unsupported BYTE_ORDER!
#endif
/* PCI R/W macros */
#if defined(__APPLE__) && defined(__MACH__)
extern struct pci_access *pacc;
#endif
extern char do4k;
/*#define PCI_IN32(a) pci_read_long(dev->pcidev, (a))
#define PCI_IN16(a) pci_read_word(dev->pcidev, (a))
#define PCI_OUT32(a,v) pci_write_long(dev->pcidev, (a), (v))
#define PCI_OUT16(a,v) pci_write_word(dev->pcidev, (a), (v))
#else*/
#define PCI_IN32(a) (*((volatile uint32_t *)(dev->mem + (a))))
#define PCI_IN16(a) (*((volatile uint16_t *)(dev->mem + (a))))
#define PCI_OUT32(a,v) (*((volatile uint32_t *)(dev->mem + (a))) = (v))
#define PCI_OUT16(a,v) (*((volatile uint16_t *)(dev->mem + (a))) = (v))
/*#endif*/
struct pcidev
{
unsigned int class,
ven, dev,
sven, sdev;
int idx;
char *device;
struct io_driver *ops;
unsigned char *mem;
bool eeprom_locked;
char *forced_driver;
#if defined(__APPLE__) && defined(__MACH__)
unsigned char config[64];
struct pci_dev *pcidev;
#endif
};
struct pci_id
{
unsigned int ven, dev;
char name[64];
};
enum byte_order
{
order_unknown = 0,
order_be,
order_le
};
extern unsigned int debug;
#define EEPROM_SIZE_MAX 0x4000
extern bool preserve_mac;
extern bool preserve_calib;
extern bool buf_read16(struct pcidev* dev, uint32_t addr, uint16_t *value);
extern bool buf_write16(struct pcidev* dev, uint32_t addr, uint16_t value);
struct io_driver {
const char *name;
const struct pci_id *valid_ids;
uint32_t mmap_size;
uint32_t eeprom_size;
uint16_t eeprom_signature;
bool eeprom_writable;
bool (*init_device)(struct pcidev *dev);
bool (*eeprom_init)(struct pcidev *dev);
bool (*eeprom_check)(struct pcidev *dev);
bool (*eeprom_lock)(struct pcidev *dev);
bool (*eeprom_release)(struct pcidev *dev);
bool (*eeprom_read16)(struct pcidev *dev, uint32_t addr, uint16_t *value);
bool (*eeprom_write16)(struct pcidev *dev, uint32_t addr, uint16_t value);
void (*eeprom_patch11n)(struct pcidev *dev);
void (*eeprom_parse)(struct pcidev *dev);
void *pdata;
};
#endif