# DRIL MFRC522 Project
## Members
- Brian BANG
- Marc DESGRANGES
## Project
### Threshold 0
The message displayed is "Welcome to GISTRE Linux !"
### Threshold 2 & 3
We defined a struct `gistre_card`. In which, `cdev` and `regmap` are initialized during the call to `init()`, `regmap` being initialized with the provided API.
```c=
struct gistre_card {
bool read;
struct cdev cdev;
struct regmap *reg;
}
```
- `write()`:
- For command parsing we used `char *strsep(char **stringp, const char *delim)`, which allowed us to tokenize the different arguments.
- On `mem_read` :`read` is set to `true`, and `false` otherwise.
- On `mem_write` : use `strsep()` in order to get the number of bytes and the string to write.
1. Flush with:
`regmap_write(dev->reg, FRC522_FIFOLEVELREG, MFRC522_FIFOLEVELREG_FLUSH);`
2. Write bytes into the `FIFODATAREG`:
```c=
for (i = 0; i < tmp; i++) {
regmap_write(dev->reg, MFRC522_FIFODATAREG, raw_data[i]);
```
- On `gen_rand_id`:
1. Flush with:
`regmap_write(dev->reg, FRC522_FIFOLEVELREG, MFRC522_FIFOLEVELREG_FLUSH);`
2. Write random bytes in the internal buffer:
`regmap_write(dev->reg, MFRC522_CMDREG, MFRC522_GENERATERANDOMID);`
3. Transfer those bytes to the `FIFODATAREG`:
`regmap_write(dev->reg, MFRC522_CMDREG, MFRC522_MEM);`
- `read()`:
- if `read` is `true`, we use `regmap_read()` to read from the `FIFODATAREG`.
- Get the number of bytes in `FIFODATAREG`:
`regmap_read(dev->reg, MFRC522_FIFOLEVELREG, &length);`
- Read as many bytes as available and fill a buffer.
- use `copy_to_user()` to fill in the given buffer.
### Bonus 2
For this part, we added a`debug` boolean attribute to our `gistre_card` struct. Using the parsing method specified above, we set `debug` to `true` if `on` is specified, to `false` if `off` is specified and unchanged for any other command.
```c=
struct gistre_card {
bool read;
bool debug;
struct cdev cdev;
struct regmap *reg;
}
```
If `debug` is at `true` while calling `write()` with `mem_write` or `gen_rand_id`, or calling `read()`; in other words actually interacting with the `FIFODATAREG` through the regmap API, bytes that are either read or written to it, will also be displayed to the user in the console.
### Bonus 4
For this bonus, we used the `of_get_property(struct device_node *dev, const char *name, int *plen)` function from `<linux/of.h>`. However while calling it as:
```c=
const char *version;
struct gistre_card *dev = kcalloc(1, sizeof(*dev), GFP_KERNEL);
struct device *d = mfrc522_find_dev();
struct mfrc522_dev *mfrc = dev_to_mfrc522(d);
version = of_get_property(d->of_node, "version", NULL);
```
we always get an empty string.