This is an automated email from the ASF dual-hosted git repository. gnutt pushed a commit to branch SocketCAN in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git
commit 9721b096865484b842b2f1ce62974fd852c4fa08 Author: Peter van der Perk <peter.vanderp...@nxp.com> AuthorDate: Wed Mar 18 12:18:30 2020 +0100 Backport code style fixes --- include/nuttx/wqueue.h | 2 +- net/can/can.h | 13 ++-- net/can/can_recvfrom.c | 191 ++++++++++++++++++++++++++----------------------- 3 files changed, 108 insertions(+), 98 deletions(-) diff --git a/include/nuttx/wqueue.h b/include/nuttx/wqueue.h index 6f88a3a..71e7112 100644 --- a/include/nuttx/wqueue.h +++ b/include/nuttx/wqueue.h @@ -289,7 +289,7 @@ enum work_evtype_e WORK_TCP_DISCONNECT, /* Notify loss of TCP connection */ WORK_UDP_READAHEAD, /* Notify that UDP read-ahead data is available */ WORK_UDP_WRITEBUFFER, /* Notify that UDP write buffer is empty */ - WORK_NETLINK_RESPONSE, /* Notify thtat Netlink response is available */ + WORK_NETLINK_RESPONSE, /* Notify that Netlink response is available */ WORK_CAN_READAHEAD /* Notify that CAN read-ahead data is available */ }; diff --git a/net/can/can.h b/net/can/can.h index a727612..2377a0c 100644 --- a/net/can/can.h +++ b/net/can/can.h @@ -104,7 +104,7 @@ struct can_conn_s */ struct can_poll_s pollinfo[4]; /* FIXME make dynamic */ - + #ifdef CONFIG_NET_CANPROTO_OPTIONS int32_t loopback; int32_t recv_own_msgs; @@ -115,12 +115,10 @@ struct can_conn_s int32_t tx_deadline; # endif #endif - + #ifdef CONFIG_NET_TIMESTAMP FAR struct socket *psock; /* Needed to get SO_TIMESTAMP value */ #endif - - }; /**************************************************************************** @@ -169,8 +167,8 @@ FAR struct can_conn_s *can_alloc(void); * Name: can_free() * * Description: - * Free a NetLink connection structure that is no longer in use. This should - * be done by the implementation of close(). + * Free a NetLink connection structure that is no longer in use. This + * should be done by the implementation of close(). * ****************************************************************************/ @@ -259,7 +257,6 @@ uint16_t can_datahandler(FAR struct can_conn_s *conn, FAR uint8_t *buffer, * ****************************************************************************/ - ssize_t can_recvfrom(FAR struct socket *psock, FAR void *buf, size_t len, int flags, FAR struct sockaddr *from, FAR socklen_t *fromlen); @@ -282,7 +279,7 @@ ssize_t can_recvfrom(FAR struct socket *psock, FAR void *buf, size_t len, * flags Receive flags (ignored) * ****************************************************************************/ -#ifdef CONFIG_NET_RECVMSG_CMSG +#ifdef CONFIG_NET_CMSG ssize_t can_recvmsg(FAR struct socket *psock, FAR struct msghdr *msg, size_t len, int flags); #endif diff --git a/net/can/can_recvfrom.c b/net/can/can_recvfrom.c index d9ed8cb..b304977 100644 --- a/net/can/can_recvfrom.c +++ b/net/can/can_recvfrom.c @@ -50,14 +50,13 @@ #include <sys/time.h> #endif - /**************************************************************************** * Private Types ****************************************************************************/ struct can_recvfrom_s { - FAR struct socket *pr_sock; /* The parent socket structure */ + FAR struct socket *pr_sock; /* The parent socket structure */ FAR struct devif_callback_s *pr_cb; /* Reference to callback instance */ sem_t pr_sem; /* Semaphore signals recv completion */ size_t pr_buflen; /* Length of receive buffer */ @@ -233,14 +232,15 @@ static inline void can_newdata(FAR struct net_driver_s *dev, static inline int can_readahead(struct can_recvfrom_s *pstate) { - FAR struct can_conn_s *conn = (FAR struct can_conn_s *)pstate->pr_sock->s_conn; + FAR struct can_conn_s *conn = + (FAR struct can_conn_s *) pstate->pr_sock->s_conn; FAR struct iob_s *iob; int recvlen; /* Check there is any CAN data already buffered in a read-ahead * buffer. */ - + pstate->pr_recvlen = -1; if ((iob = iob_peek_queue(&conn->readahead)) != NULL && @@ -287,15 +287,16 @@ static inline int can_readahead(struct can_recvfrom_s *pstate) IOBUSER_NET_CAN_READAHEAD); } - /* do not pass frames with DLC > 8 to a legacy socket */ - if (!conn->fd_frames) - { - struct canfd_frame *cfd = (struct canfd_frame *)pstate->pr_buffer; - if (cfd->len > CAN_MAX_DLEN) - { - return 0; - } - } + /* do not pass frames with DLC > 8 to a legacy socket */ + + if (!conn->fd_frames) + { + struct canfd_frame *cfd = (struct canfd_frame *)pstate->pr_buffer; + if (cfd->len > CAN_MAX_DLEN) + { + return 0; + } + } return recvlen; } @@ -319,13 +320,14 @@ static inline int can_readahead(struct can_recvfrom_s *pstate) * The network is locked. * ****************************************************************************/ + #ifdef CONFIG_NET_TIMESTAMP -static inline int can_readahead_timestamp(struct can_conn_s *conn, FAR uint8_t *buffer) +static inline int can_readahead_timestamp(struct can_conn_s *conn, + FAR uint8_t *buffer) { FAR struct iob_s *iob; int recvlen; - if ((iob = iob_peek_queue(&conn->readahead)) != NULL) { DEBUGASSERT(iob->io_pktlen > 0); @@ -379,26 +381,27 @@ static inline int can_readahead_timestamp(struct can_conn_s *conn, FAR uint8_t * #ifdef CONFIG_NET_CANPROTO_OPTIONS static int can_recv_filter(struct can_conn_s *conn, canid_t id) { - for(int i = 0; i < conn->filter_count; i++) + for (int i = 0; i < conn->filter_count; i++) { - if (conn->filters[i].can_id & CAN_INV_FILTER) - { - if((id & conn->filters[i].can_mask) != - ((conn->filters[i].can_id & ~CAN_INV_FILTER) - & conn->filters[i].can_mask)) - { - return 1; - } - } - else - { - if((id & conn->filters[i].can_mask) == - (conn->filters[i].can_id & conn->filters[i].can_mask)) - { - return 1; - } - } + if (conn->filters[i].can_id & CAN_INV_FILTER) + { + if ((id & conn->filters[i].can_mask) != + ((conn->filters[i].can_id & ~CAN_INV_FILTER) & + conn->filters[i].can_mask)) + { + return 1; + } + } + else + { + if ((id & conn->filters[i].can_mask) == + (conn->filters[i].can_id & conn->filters[i].can_mask)) + { + return 1; + } + } } + return 0; } #endif @@ -416,46 +419,50 @@ static uint16_t can_recvfrom_eventhandler(FAR struct net_driver_s *dev, { if ((flags & CAN_NEWDATA) != 0) { - /* If a new packet is available, check receive filters - * when is valid then complete the read action. */ + /* If a new packet is available, check receive filters + * when is valid then complete the read action. + */ #ifdef CONFIG_NET_CANPROTO_OPTIONS - if(can_recv_filter(conn,(canid_t)*dev->d_appdata) == 0) - { - flags &= ~CAN_NEWDATA; - return flags; - } + if (can_recv_filter(conn, (canid_t) *dev->d_appdata) == 0) + { + flags &= ~CAN_NEWDATA; + return flags; + } #endif - /* do not pass frames with DLC > 8 to a legacy socket */ - if (!conn->fd_frames) - { - struct canfd_frame *cfd = (struct canfd_frame*)dev->d_appdata; - if (cfd->len > CAN_MAX_DLEN) - { - /* DO WE NEED TO CLEAR FLAGS?? */ - flags &= ~CAN_NEWDATA; - return flags; - } - } + /* do not pass frames with DLC > 8 to a legacy socket */ + + if (!conn->fd_frames) + { + struct canfd_frame *cfd = (struct canfd_frame *)dev->d_appdata; + if (cfd->len > CAN_MAX_DLEN) + { + /* DO WE NEED TO CLEAR FLAGS?? */ + + flags &= ~CAN_NEWDATA; + return flags; + } + } /* Copy the packet */ can_newdata(dev, pstate); #ifdef CONFIG_NET_TIMESTAMP - if(pstate->pr_sock->s_timestamp) - { - if(pstate->pr_msglen == sizeof(struct timeval)) - { - can_readahead_timestamp(conn, pstate->pr_msgbuf); - } - else - { - /* We still have to consume the data otherwise IOB gets full */ - uint8_t dummy_buf[sizeof(struct timeval)]; - can_readahead_timestamp(conn, &dummy_buf); - } - } + if (pstate->pr_sock->s_timestamp) + { + if (pstate->pr_msglen == sizeof(struct timeval)) + { + can_readahead_timestamp(conn, pstate->pr_msgbuf); + } + else + { + /* We still have to consume the data otherwise IOB gets full */ + + uint8_t dummy_buf[sizeof(struct timeval)]; + can_readahead_timestamp(conn, &dummy_buf); + } + } #endif /* We are finished. */ @@ -508,6 +515,7 @@ static ssize_t can_recvfrom_result(int result, if (pstate->pr_result < 0) { /* This might return EAGAIN on a timeout */ + return pstate->pr_result; } @@ -592,10 +600,10 @@ ssize_t can_recvfrom(FAR struct socket *psock, FAR void *buf, ret = can_readahead(&state); if (ret > 0) - { + { goto errout_with_state; } - + ret = state.pr_recvlen; /* Handle non-blocking CAN sockets */ @@ -610,7 +618,7 @@ ssize_t can_recvfrom(FAR struct socket *psock, FAR void *buf, { /* Nothing was received */ - ret = -EAGAIN; + ret = -EAGAIN; goto errout_with_state; } } @@ -675,7 +683,8 @@ errout_with_state: * flags Receive flags (ignored) * ****************************************************************************/ -#ifdef CONFIG_NET_RECVMSG_CMSG + +#ifdef CONFIG_NET_CMSG ssize_t can_recvmsg(FAR struct socket *psock, FAR struct msghdr *msg, size_t len, int flags) { @@ -707,20 +716,22 @@ ssize_t can_recvmsg(FAR struct socket *psock, FAR struct msghdr *msg, nxsem_init(&state.pr_sem, 0, 0); /* Doesn't really fail */ nxsem_setprotocol(&state.pr_sem, SEM_PRIO_NONE); - state.pr_buflen = msg->msg_iov->iov_len; state.pr_buffer = msg->msg_iov->iov_base; + #ifdef CONFIG_NET_TIMESTAMP - if(psock->s_timestamp && msg->msg_controllen == (sizeof(struct cmsghdr) + sizeof(struct timeval))) + if (psock->s_timestamp && msg->msg_controllen == + (sizeof(struct cmsghdr) + sizeof(struct timeval))) { - struct cmsghdr* cmsg = CMSG_FIRSTHDR(msg); - state.pr_msglen = sizeof(struct timeval); - state.pr_msgbuf = CMSG_DATA(cmsg); - cmsg->cmsg_level = SOL_SOCKET; - cmsg->cmsg_type = SO_TIMESTAMP; - cmsg->cmsg_len = state.pr_msglen; + struct cmsghdr *cmsg = CMSG_FIRSTHDR(msg); + state.pr_msglen = sizeof(struct timeval); + state.pr_msgbuf = CMSG_DATA(cmsg); + cmsg->cmsg_level = SOL_SOCKET; + cmsg->cmsg_type = SO_TIMESTAMP; + cmsg->cmsg_len = state.pr_msglen; } #endif + state.pr_sock = psock; /* Handle any any CAN data already buffered in a read-ahead buffer. NOTE @@ -732,20 +743,22 @@ ssize_t can_recvmsg(FAR struct socket *psock, FAR struct msghdr *msg, if (ret > 0) { #ifdef CONFIG_NET_TIMESTAMP - if(psock->s_timestamp) - { - if(state.pr_msglen == sizeof(struct timeval)) - { - can_readahead_timestamp(conn, state.pr_msgbuf); - } - else - { - /* We still have to consume the data otherwise IOB gets full */ - uint8_t dummy_buf[sizeof(struct timeval)]; - can_readahead_timestamp(conn, &dummy_buf); - } - } + if (psock->s_timestamp) + { + if (state.pr_msglen == sizeof(struct timeval)) + { + can_readahead_timestamp(conn, state.pr_msgbuf); + } + else + { + /* We still have to consume the data otherwise IOB gets full */ + + uint8_t dummy_buf[sizeof(struct timeval)]; + can_readahead_timestamp(conn, &dummy_buf); + } + } #endif + goto errout_with_state; }