Re: How to send a CAN message while in a kernel module?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Thank you for all the direction Oliver,  I think I am on the correct path,
but now have can_send returning with a "-1" (ERESTART). I used raw_sendmsg
as a template for this and cut out (hopefully) unneeded code, but I am
concerned I cut out something I needed.  Would you mind taking another look?

Thanks.

int SendCanTime(struct timespec *tsCurrentTime) {

  struct sk_buff *skb;
  struct can_frame *frame = kmalloc(sizeof (struct can_frame), GFP_KERNEL);
  struct net_device *dev;
  int err = 0;
  int thetime = tsCurrentTime->tv_sec;

  // Set up can frame
  frame->can_id = 0x00050F93 | CAN_EFF_FLAG;
  frame->can_dlc = 6;
  frame->data[0] = 0x00;
  frame->data[1] = 0x02;
  memcpy(frame->data+2, &thetime, sizeof(int));

  // Find the netdevice named can0
  read_lock(&dev_base_lock);
  dev = first_net_device(&init_net);
  while (!strcmp(dev->name, "can0")) {
    printk(KERN_INFO "found [%s]\n", dev->name);
    dev = next_net_device(dev);
  }
  read_unlock(&dev_base_lock);

  if (!dev)
    return -ENXIO;

  // Create skb
  skb = alloc_can_skb(dev, &frame);
  if (!skb)
    goto put_dev;

  skb->dev = dev;

  err = can_send(skb, 0);

  dev_put(dev);

  if (err)
    goto send_failed;

  return 0;

//kfree_skb(skb);
put_dev:
  dev_put(dev);
send_failed:
  return err;

}
                                                                               ^



[Index of Archives]     [Automotive Discussions]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [eCos]     [Asterisk Internet PBX]     [Linux API]     [CAN Bus]

  Powered by Linux