-ssize_t can_read(struct file *file, char *buffer, size_t length, loff_t *offset)
-{
- struct msgobj_t *obj;
- struct chip_t *chip;
- struct canfifo_t *fifo;
- struct canmsg_t read_msg;
- int ret=0;
-
- if (length < sizeof(struct canmsg_t)) {
- DEBUGMSG("Trying to read less bytes than a CAN message, \n");
- DEBUGMSG("this will always return zero.\n");
- return 0;
- }
- if (length > 8 * sizeof(struct canmsg_t)) {
- DEBUGMSG("Reading more than 8 CAN messages, this is not supported.\n");
- DEBUGMSG("Defaulting to 8 messages.\n");
- length = 8 * sizeof(struct canmsg_t);
- }
- /* Initialize hardware pointers */
- if ( (obj = objects_p[MINOR_NR]) == NULL) {
- CANMSG("Could not assign buffer structure\n");
- return -1;
- }
- if ( (chip = obj->hostchip) == NULL) {
- CANMSG("Device is not correctly configured,\n");
- CANMSG("please reload the driver.\n");
- return -1;
- }
- if ( (fifo = obj->fifo) == NULL) {
- CANMSG("Could not assign buffer memory.\n");
- return -1;
- }
-
- copy_from_user(&read_msg, buffer, sizeof(struct canmsg_t));
- if (read_msg.flags & MSG_RTR)
- ret = can_rtr_read(chip, obj, buffer);
- else
- ret = can_std_read(file, fifo, obj, buffer, length);
-
- return ret;
-}
-
-