I am writing a network driver that should send packets to an Arduino using Serial communication. This is a homework assignment and this is only for educational purposes. Please, take that into account before suggesting that everything could be accomplished in user space.
This answer stated about filp_open
and filp_close
, and I thought that I could use them to open /dev/ttyACMx
or /dev/ttyUSBx
, but I read somewhere else that it is not a good idea to use I/O file operations inside the kernel, so I am looking for a better approach.
I have also read about outb
and inb
, but I have not found any way to get the port
number argument required for both functions. I have tried using lsusb and writing to some of those 0xXX
endpoint addresses but it did not work.
This is my transmit function, where I want to, instead of printing, writing to a serial port. My aux variable is just a union
that contains two members: struct sk_buff skb
and unsigned char bytes[sizeof(struct sk_buff)]
. But at this point in the assignment, I just want to send the contents of skb.data
to my Arduino serial.
aux = skb;
while(aux != NULL) {
p.skb = *aux;
for(i = 0; i < p.skb.len; i++) {
if(i == 0) {
printk(KERN_INFO "\\%02x", p.skb.data[i]);
}
else {
printk(KERN_CONT "\\%02x", p.skb.data[i]);
}
}
aux = aux->next;
}
And this is Arduino code is the following:
void setup() {
Serial.begin(9600);
Serial.println("Start");
}
void loop() {
while(Serial.available() > 0)
Serial.print(Serial.read());
Serial.println();
}
It is simple as that. I want to read the content of a packet inside my Arduino. How can I write in a /dev/ttyACMx
or /dev/ttyUSBx
port inside my network driver?