• Home
  • Raw
  • Download

Lines Matching full:so

161 	struct isotp_sock *so = container_of(hrtimer, struct isotp_sock,  in isotp_rx_timer_handler()  local
163 struct sock *sk = &so->sk; in isotp_rx_timer_handler()
165 if (so->rx.state == ISOTP_WAIT_DATA) { in isotp_rx_timer_handler()
174 so->rx.state = ISOTP_IDLE; in isotp_rx_timer_handler()
185 struct isotp_sock *so = isotp_sk(sk); in isotp_send_fc() local
188 nskb = alloc_skb(so->ll.mtu + sizeof(struct can_skb_priv), gfp_any()); in isotp_send_fc()
192 dev = dev_get_by_index(sock_net(sk), so->ifindex); in isotp_send_fc()
205 skb_put_zero(nskb, so->ll.mtu); in isotp_send_fc()
208 ncf->can_id = so->txid; in isotp_send_fc()
210 if (so->opt.flags & CAN_ISOTP_TX_PADDING) { in isotp_send_fc()
211 memset(ncf->data, so->opt.txpad_content, CAN_MAX_DLEN); in isotp_send_fc()
218 ncf->data[ae + 1] = so->rxfc.bs; in isotp_send_fc()
219 ncf->data[ae + 2] = so->rxfc.stmin; in isotp_send_fc()
222 ncf->data[0] = so->opt.ext_address; in isotp_send_fc()
224 ncf->flags = so->ll.tx_flags; in isotp_send_fc()
234 so->rx.bs = 0; in isotp_send_fc()
237 so->lastrxcf_tstamp = ktime_set(0, 0); in isotp_send_fc()
240 hrtimer_start(&so->rxtimer, ktime_set(1, 0), HRTIMER_MODE_REL_SOFT); in isotp_send_fc()
298 static int check_pad(struct isotp_sock *so, struct canfd_frame *cf, in check_pad() argument
304 if (!(so->opt.flags & CAN_ISOTP_RX_PADDING)) { in check_pad()
305 if (so->opt.flags & CAN_ISOTP_CHK_PAD_LEN) in check_pad()
313 if ((so->opt.flags & CAN_ISOTP_CHK_PAD_LEN) && in check_pad()
318 if (so->opt.flags & CAN_ISOTP_CHK_PAD_DATA) { in check_pad()
326 static int isotp_rcv_fc(struct isotp_sock *so, struct canfd_frame *cf, int ae) in isotp_rcv_fc() argument
328 struct sock *sk = &so->sk; in isotp_rcv_fc()
330 if (so->tx.state != ISOTP_WAIT_FC && in isotp_rcv_fc()
331 so->tx.state != ISOTP_WAIT_FIRST_FC) in isotp_rcv_fc()
334 hrtimer_cancel(&so->txtimer); in isotp_rcv_fc()
337 ((so->opt.flags & ISOTP_CHECK_PADDING) && in isotp_rcv_fc()
338 check_pad(so, cf, ae + FC_CONTENT_SZ, so->opt.rxpad_content))) { in isotp_rcv_fc()
344 so->tx.state = ISOTP_IDLE; in isotp_rcv_fc()
345 wake_up_interruptible(&so->wait); in isotp_rcv_fc()
350 if (so->tx.state == ISOTP_WAIT_FIRST_FC) { in isotp_rcv_fc()
351 so->txfc.bs = cf->data[ae + 1]; in isotp_rcv_fc()
352 so->txfc.stmin = cf->data[ae + 2]; in isotp_rcv_fc()
355 if (so->txfc.stmin > 0x7F && in isotp_rcv_fc()
356 (so->txfc.stmin < 0xF1 || so->txfc.stmin > 0xF9)) in isotp_rcv_fc()
357 so->txfc.stmin = 0x7F; in isotp_rcv_fc()
359 so->tx_gap = ktime_set(0, 0); in isotp_rcv_fc()
361 so->tx_gap = ktime_add_ns(so->tx_gap, so->opt.frame_txtime); in isotp_rcv_fc()
363 if (so->opt.flags & CAN_ISOTP_FORCE_TXSTMIN) in isotp_rcv_fc()
364 so->tx_gap = ktime_add_ns(so->tx_gap, in isotp_rcv_fc()
365 so->force_tx_stmin); in isotp_rcv_fc()
366 else if (so->txfc.stmin < 0x80) in isotp_rcv_fc()
367 so->tx_gap = ktime_add_ns(so->tx_gap, in isotp_rcv_fc()
368 so->txfc.stmin * 1000000); in isotp_rcv_fc()
370 so->tx_gap = ktime_add_ns(so->tx_gap, in isotp_rcv_fc()
371 (so->txfc.stmin - 0xF0) in isotp_rcv_fc()
373 so->tx.state = ISOTP_WAIT_FC; in isotp_rcv_fc()
378 so->tx.bs = 0; in isotp_rcv_fc()
379 so->tx.state = ISOTP_SENDING; in isotp_rcv_fc()
381 hrtimer_start(&so->txtimer, so->tx_gap, in isotp_rcv_fc()
387 hrtimer_start(&so->txtimer, ktime_set(1, 0), in isotp_rcv_fc()
400 so->tx.state = ISOTP_IDLE; in isotp_rcv_fc()
401 wake_up_interruptible(&so->wait); in isotp_rcv_fc()
409 struct isotp_sock *so = isotp_sk(sk); in isotp_rcv_sf() local
412 hrtimer_cancel(&so->rxtimer); in isotp_rcv_sf()
413 so->rx.state = ISOTP_IDLE; in isotp_rcv_sf()
418 if ((so->opt.flags & ISOTP_CHECK_PADDING) && in isotp_rcv_sf()
419 check_pad(so, cf, pcilen + len, so->opt.rxpad_content)) { in isotp_rcv_sf()
441 struct isotp_sock *so = isotp_sk(sk); in isotp_rcv_ff() local
446 hrtimer_cancel(&so->rxtimer); in isotp_rcv_ff()
447 so->rx.state = ISOTP_IDLE; in isotp_rcv_ff()
450 so->rx.ll_dl = padlen(cf->len); in isotp_rcv_ff()
453 if (cf->len != so->rx.ll_dl) in isotp_rcv_ff()
457 so->rx.len = (cf->data[ae] & 0x0F) << 8; in isotp_rcv_ff()
458 so->rx.len += cf->data[ae + 1]; in isotp_rcv_ff()
461 if (so->rx.len) { in isotp_rcv_ff()
465 so->rx.len = cf->data[ae + 2] << 24; in isotp_rcv_ff()
466 so->rx.len += cf->data[ae + 3] << 16; in isotp_rcv_ff()
467 so->rx.len += cf->data[ae + 4] << 8; in isotp_rcv_ff()
468 so->rx.len += cf->data[ae + 5]; in isotp_rcv_ff()
473 off = (so->rx.ll_dl > CAN_MAX_DLEN) ? 1 : 0; in isotp_rcv_ff()
475 if (so->rx.len + ae + off + ff_pci_sz < so->rx.ll_dl) in isotp_rcv_ff()
478 if (so->rx.len > MAX_MSG_LENGTH) { in isotp_rcv_ff()
485 so->rx.idx = 0; in isotp_rcv_ff()
486 for (i = ae + ff_pci_sz; i < so->rx.ll_dl; i++) in isotp_rcv_ff()
487 so->rx.buf[so->rx.idx++] = cf->data[i]; in isotp_rcv_ff()
490 so->rx.sn = 1; in isotp_rcv_ff()
491 so->rx.state = ISOTP_WAIT_DATA; in isotp_rcv_ff()
494 if (so->opt.flags & CAN_ISOTP_LISTEN_MODE) in isotp_rcv_ff()
505 struct isotp_sock *so = isotp_sk(sk); in isotp_rcv_cf() local
509 if (so->rx.state != ISOTP_WAIT_DATA) in isotp_rcv_cf()
513 if (so->opt.flags & CAN_ISOTP_FORCE_RXSTMIN) { in isotp_rcv_cf()
514 if (ktime_to_ns(ktime_sub(skb->tstamp, so->lastrxcf_tstamp)) < in isotp_rcv_cf()
515 so->force_rx_stmin) in isotp_rcv_cf()
518 so->lastrxcf_tstamp = skb->tstamp; in isotp_rcv_cf()
521 hrtimer_cancel(&so->rxtimer); in isotp_rcv_cf()
524 if (cf->len > so->rx.ll_dl) in isotp_rcv_cf()
528 if (cf->len < so->rx.ll_dl) { in isotp_rcv_cf()
530 if (so->rx.len - so->rx.idx > so->rx.ll_dl - ae - N_PCI_SZ) in isotp_rcv_cf()
534 if ((cf->data[ae] & 0x0F) != so->rx.sn) { in isotp_rcv_cf()
541 so->rx.state = ISOTP_IDLE; in isotp_rcv_cf()
544 so->rx.sn++; in isotp_rcv_cf()
545 so->rx.sn %= 16; in isotp_rcv_cf()
548 so->rx.buf[so->rx.idx++] = cf->data[i]; in isotp_rcv_cf()
549 if (so->rx.idx >= so->rx.len) in isotp_rcv_cf()
553 if (so->rx.idx >= so->rx.len) { in isotp_rcv_cf()
555 so->rx.state = ISOTP_IDLE; in isotp_rcv_cf()
557 if ((so->opt.flags & ISOTP_CHECK_PADDING) && in isotp_rcv_cf()
558 check_pad(so, cf, i + 1, so->opt.rxpad_content)) { in isotp_rcv_cf()
566 nskb = alloc_skb(so->rx.len, gfp_any()); in isotp_rcv_cf()
570 memcpy(skb_put(nskb, so->rx.len), so->rx.buf, in isotp_rcv_cf()
571 so->rx.len); in isotp_rcv_cf()
580 if (!so->rxfc.bs || ++so->rx.bs < so->rxfc.bs) { in isotp_rcv_cf()
582 hrtimer_start(&so->rxtimer, ktime_set(1, 0), in isotp_rcv_cf()
588 if (so->opt.flags & CAN_ISOTP_LISTEN_MODE) in isotp_rcv_cf()
591 /* we reached the specified blocksize so->rxfc.bs */ in isotp_rcv_cf()
599 struct isotp_sock *so = isotp_sk(sk); in isotp_rcv() local
601 int ae = (so->opt.flags & CAN_ISOTP_EXTEND_ADDR) ? 1 : 0; in isotp_rcv()
607 if (skb->len != so->ll.mtu) in isotp_rcv()
613 if (ae && cf->data[0] != so->opt.rx_ext_address) in isotp_rcv()
618 if (so->opt.flags & CAN_ISOTP_HALF_DUPLEX) { in isotp_rcv()
620 if ((so->tx.state != ISOTP_IDLE && n_pci_type != N_PCI_FC) || in isotp_rcv()
621 (so->rx.state != ISOTP_IDLE && n_pci_type == N_PCI_FC)) in isotp_rcv()
628 isotp_rcv_fc(so, cf, ae); in isotp_rcv()
649 * If so take care of the increased SF PCI size in isotp_rcv()
673 static void isotp_fill_dataframe(struct canfd_frame *cf, struct isotp_sock *so, in isotp_fill_dataframe() argument
677 int space = so->tx.ll_dl - pcilen; in isotp_fill_dataframe()
678 int num = min_t(int, so->tx.len - so->tx.idx, space); in isotp_fill_dataframe()
681 cf->can_id = so->txid; in isotp_fill_dataframe()
685 if (so->opt.flags & CAN_ISOTP_TX_PADDING) { in isotp_fill_dataframe()
688 memset(cf->data, so->opt.txpad_content, cf->len); in isotp_fill_dataframe()
698 cf->data[pcilen + i] = so->tx.buf[so->tx.idx++]; in isotp_fill_dataframe()
701 cf->data[0] = so->opt.ext_address; in isotp_fill_dataframe()
704 static void isotp_create_fframe(struct canfd_frame *cf, struct isotp_sock *so, in isotp_create_fframe() argument
710 cf->can_id = so->txid; in isotp_create_fframe()
711 cf->len = so->tx.ll_dl; in isotp_create_fframe()
713 cf->data[0] = so->opt.ext_address; in isotp_create_fframe()
716 if (so->tx.len > 4095) { in isotp_create_fframe()
720 cf->data[ae + 2] = (u8)(so->tx.len >> 24) & 0xFFU; in isotp_create_fframe()
721 cf->data[ae + 3] = (u8)(so->tx.len >> 16) & 0xFFU; in isotp_create_fframe()
722 cf->data[ae + 4] = (u8)(so->tx.len >> 8) & 0xFFU; in isotp_create_fframe()
723 cf->data[ae + 5] = (u8)so->tx.len & 0xFFU; in isotp_create_fframe()
727 cf->data[ae] = (u8)(so->tx.len >> 8) | N_PCI_FF; in isotp_create_fframe()
728 cf->data[ae + 1] = (u8)so->tx.len & 0xFFU; in isotp_create_fframe()
733 for (i = ae + ff_pci_sz; i < so->tx.ll_dl; i++) in isotp_create_fframe()
734 cf->data[i] = so->tx.buf[so->tx.idx++]; in isotp_create_fframe()
736 so->tx.sn = 1; in isotp_create_fframe()
737 so->tx.state = ISOTP_WAIT_FIRST_FC; in isotp_create_fframe()
742 struct isotp_sock *so = container_of(hrtimer, struct isotp_sock, in isotp_tx_timer_handler() local
744 struct sock *sk = &so->sk; in isotp_tx_timer_handler()
750 int ae = (so->opt.flags & CAN_ISOTP_EXTEND_ADDR) ? 1 : 0; in isotp_tx_timer_handler()
752 switch (so->tx.state) { in isotp_tx_timer_handler()
764 so->tx.state = ISOTP_IDLE; in isotp_tx_timer_handler()
765 wake_up_interruptible(&so->wait); in isotp_tx_timer_handler()
771 dev = dev_get_by_index(sock_net(sk), so->ifindex); in isotp_tx_timer_handler()
776 skb = alloc_skb(so->ll.mtu + sizeof(struct can_skb_priv), in isotp_tx_timer_handler()
788 skb_put_zero(skb, so->ll.mtu); in isotp_tx_timer_handler()
791 isotp_fill_dataframe(cf, so, ae, 0); in isotp_tx_timer_handler()
794 cf->data[ae] = N_PCI_CF | so->tx.sn++; in isotp_tx_timer_handler()
795 so->tx.sn %= 16; in isotp_tx_timer_handler()
796 so->tx.bs++; in isotp_tx_timer_handler()
798 cf->flags = so->ll.tx_flags; in isotp_tx_timer_handler()
808 if (so->tx.idx >= so->tx.len) { in isotp_tx_timer_handler()
810 so->tx.state = ISOTP_IDLE; in isotp_tx_timer_handler()
812 wake_up_interruptible(&so->wait); in isotp_tx_timer_handler()
816 if (so->txfc.bs && so->tx.bs >= so->txfc.bs) { in isotp_tx_timer_handler()
818 so->tx.state = ISOTP_WAIT_FC; in isotp_tx_timer_handler()
820 hrtimer_set_expires(&so->txtimer, in isotp_tx_timer_handler()
828 if (!so->tx_gap) in isotp_tx_timer_handler()
833 hrtimer_set_expires(&so->txtimer, in isotp_tx_timer_handler()
834 ktime_add(ktime_get(), so->tx_gap)); in isotp_tx_timer_handler()
848 struct isotp_sock *so = isotp_sk(sk); in isotp_sendmsg() local
849 u32 old_state = so->tx.state; in isotp_sendmsg()
853 int ae = (so->opt.flags & CAN_ISOTP_EXTEND_ADDR) ? 1 : 0; in isotp_sendmsg()
854 int wait_tx_done = (so->opt.flags & CAN_ISOTP_WAIT_TX_DONE) ? 1 : 0; in isotp_sendmsg()
858 if (!so->bound) in isotp_sendmsg()
862 if (cmpxchg(&so->tx.state, ISOTP_IDLE, ISOTP_SENDING) != ISOTP_IDLE || in isotp_sendmsg()
863 wq_has_sleeper(&so->wait)) { in isotp_sendmsg()
870 err = wait_event_interruptible(so->wait, so->tx.state == ISOTP_IDLE); in isotp_sendmsg()
880 err = memcpy_from_msg(so->tx.buf, msg, size); in isotp_sendmsg()
884 dev = dev_get_by_index(sock_net(sk), so->ifindex); in isotp_sendmsg()
890 skb = sock_alloc_send_skb(sk, so->ll.mtu + sizeof(struct can_skb_priv), in isotp_sendmsg()
901 so->tx.len = size; in isotp_sendmsg()
902 so->tx.idx = 0; in isotp_sendmsg()
905 skb_put_zero(skb, so->ll.mtu); in isotp_sendmsg()
908 off = (so->tx.ll_dl > CAN_MAX_DLEN) ? 1 : 0; in isotp_sendmsg()
911 if (size <= so->tx.ll_dl - SF_PCI_SZ4 - ae - off) { in isotp_sendmsg()
924 isotp_fill_dataframe(cf, so, ae, off); in isotp_sendmsg()
935 so->tx.state = ISOTP_IDLE; in isotp_sendmsg()
936 wake_up_interruptible(&so->wait); in isotp_sendmsg()
943 isotp_create_fframe(cf, so, ae); in isotp_sendmsg()
946 hrtimer_start(&so->txtimer, ktime_set(1, 0), HRTIMER_MODE_REL_SOFT); in isotp_sendmsg()
950 cf->flags = so->ll.tx_flags; in isotp_sendmsg()
964 wait_event_interruptible(so->wait, so->tx.state == ISOTP_IDLE); in isotp_sendmsg()
973 so->tx.state = old_state; in isotp_sendmsg()
974 if (so->tx.state == ISOTP_IDLE) in isotp_sendmsg()
975 wake_up_interruptible(&so->wait); in isotp_sendmsg()
1022 struct isotp_sock *so; in isotp_release() local
1028 so = isotp_sk(sk); in isotp_release()
1032 wait_event_interruptible(so->wait, so->tx.state == ISOTP_IDLE); in isotp_release()
1035 while (isotp_busy_notifier == so) { in isotp_release()
1040 list_del(&so->notifier); in isotp_release()
1046 if (so->bound) { in isotp_release()
1047 if (so->ifindex) { in isotp_release()
1050 dev = dev_get_by_index(net, so->ifindex); in isotp_release()
1052 can_rx_unregister(net, dev, so->rxid, in isotp_release()
1053 SINGLE_MASK(so->rxid), in isotp_release()
1061 hrtimer_cancel(&so->txtimer); in isotp_release()
1062 hrtimer_cancel(&so->rxtimer); in isotp_release()
1064 so->ifindex = 0; in isotp_release()
1065 so->bound = 0; in isotp_release()
1080 struct isotp_sock *so = isotp_sk(sk); in isotp_bind() local
1102 if (so->bound && addr->can_ifindex == so->ifindex && in isotp_bind()
1103 addr->can_addr.tp.rx_id == so->rxid && in isotp_bind()
1104 addr->can_addr.tp.tx_id == so->txid) in isotp_bind()
1117 if (dev->mtu < so->ll.mtu) { in isotp_bind()
1133 if (so->bound) { in isotp_bind()
1135 if (so->ifindex) { in isotp_bind()
1136 dev = dev_get_by_index(net, so->ifindex); in isotp_bind()
1138 can_rx_unregister(net, dev, so->rxid, in isotp_bind()
1139 SINGLE_MASK(so->rxid), in isotp_bind()
1147 so->ifindex = ifindex; in isotp_bind()
1148 so->rxid = addr->can_addr.tp.rx_id; in isotp_bind()
1149 so->txid = addr->can_addr.tp.tx_id; in isotp_bind()
1150 so->bound = 1; in isotp_bind()
1168 struct isotp_sock *so = isotp_sk(sk); in isotp_getname() local
1175 addr->can_ifindex = so->ifindex; in isotp_getname()
1176 addr->can_addr.tp.rx_id = so->rxid; in isotp_getname()
1177 addr->can_addr.tp.tx_id = so->txid; in isotp_getname()
1186 struct isotp_sock *so = isotp_sk(sk); in isotp_setsockopt() local
1192 if (so->bound) in isotp_setsockopt()
1200 if (copy_from_sockptr(&so->opt, optval, optlen)) in isotp_setsockopt()
1204 if (!(so->opt.flags & CAN_ISOTP_RX_EXT_ADDR)) in isotp_setsockopt()
1205 so->opt.rx_ext_address = so->opt.ext_address; in isotp_setsockopt()
1212 if (copy_from_sockptr(&so->rxfc, optval, optlen)) in isotp_setsockopt()
1220 if (copy_from_sockptr(&so->force_tx_stmin, optval, optlen)) in isotp_setsockopt()
1228 if (copy_from_sockptr(&so->force_rx_stmin, optval, optlen)) in isotp_setsockopt()
1250 memcpy(&so->ll, &ll, sizeof(ll)); in isotp_setsockopt()
1253 so->tx.ll_dl = ll.tx_dl; in isotp_setsockopt()
1270 struct isotp_sock *so = isotp_sk(sk); in isotp_getsockopt() local
1284 val = &so->opt; in isotp_getsockopt()
1289 val = &so->rxfc; in isotp_getsockopt()
1294 val = &so->force_tx_stmin; in isotp_getsockopt()
1299 val = &so->force_rx_stmin; in isotp_getsockopt()
1304 val = &so->ll; in isotp_getsockopt()
1318 static void isotp_notify(struct isotp_sock *so, unsigned long msg, in isotp_notify() argument
1321 struct sock *sk = &so->sk; in isotp_notify()
1326 if (so->ifindex != dev->ifindex) in isotp_notify()
1333 if (so->bound) in isotp_notify()
1334 can_rx_unregister(dev_net(dev), dev, so->rxid, in isotp_notify()
1335 SINGLE_MASK(so->rxid), in isotp_notify()
1338 so->ifindex = 0; in isotp_notify()
1339 so->bound = 0; in isotp_notify()
1380 struct isotp_sock *so = isotp_sk(sk); in isotp_init() local
1382 so->ifindex = 0; in isotp_init()
1383 so->bound = 0; in isotp_init()
1385 so->opt.flags = CAN_ISOTP_DEFAULT_FLAGS; in isotp_init()
1386 so->opt.ext_address = CAN_ISOTP_DEFAULT_EXT_ADDRESS; in isotp_init()
1387 so->opt.rx_ext_address = CAN_ISOTP_DEFAULT_EXT_ADDRESS; in isotp_init()
1388 so->opt.rxpad_content = CAN_ISOTP_DEFAULT_PAD_CONTENT; in isotp_init()
1389 so->opt.txpad_content = CAN_ISOTP_DEFAULT_PAD_CONTENT; in isotp_init()
1390 so->opt.frame_txtime = CAN_ISOTP_DEFAULT_FRAME_TXTIME; in isotp_init()
1391 so->rxfc.bs = CAN_ISOTP_DEFAULT_RECV_BS; in isotp_init()
1392 so->rxfc.stmin = CAN_ISOTP_DEFAULT_RECV_STMIN; in isotp_init()
1393 so->rxfc.wftmax = CAN_ISOTP_DEFAULT_RECV_WFTMAX; in isotp_init()
1394 so->ll.mtu = CAN_ISOTP_DEFAULT_LL_MTU; in isotp_init()
1395 so->ll.tx_dl = CAN_ISOTP_DEFAULT_LL_TX_DL; in isotp_init()
1396 so->ll.tx_flags = CAN_ISOTP_DEFAULT_LL_TX_FLAGS; in isotp_init()
1399 so->tx.ll_dl = so->ll.tx_dl; in isotp_init()
1401 so->rx.state = ISOTP_IDLE; in isotp_init()
1402 so->tx.state = ISOTP_IDLE; in isotp_init()
1404 hrtimer_init(&so->rxtimer, CLOCK_MONOTONIC, HRTIMER_MODE_REL_SOFT); in isotp_init()
1405 so->rxtimer.function = isotp_rx_timer_handler; in isotp_init()
1406 hrtimer_init(&so->txtimer, CLOCK_MONOTONIC, HRTIMER_MODE_REL_SOFT); in isotp_init()
1407 so->txtimer.function = isotp_tx_timer_handler; in isotp_init()
1409 init_waitqueue_head(&so->wait); in isotp_init()
1412 list_add_tail(&so->notifier, &isotp_notifier_list); in isotp_init()