2013/4/30 Andrzej Pietrasiewicz: > As I already wrote I am now stuck with sending correct data, so that when > I sendto() from host I can recvfrom() on device (or vice versa). payload data doesn't matter so you don't need my dumps, maybe you are using the same address on both sides of the link or you are sending to the wrong address or the route isn't set up correctly I'm attaching a test program that works with my phone but this is only the host part because I don't know how to set up the device part, can you share the details of your setup? According to Documentation/networking/phonet.txt it should be possible to do both parts on the same machine, that would test only the phonet module and not cdc_phonet ("Each socket [...] can send and receive packets with any other peer"). -- Daniele Forsi
/* G N O K I I A Linux/Unix toolset and driver for the mobile phones. This file is part of gnokii. Gnokii is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. Gnokii is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with gnokii; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Copyright (C) 2010, 2013 Daniele Forsi This is a test for accessing the phone via the phonet Linux kernel module. */ #include <sys/socket.h> #include <linux/phonet.h> #include <stdio.h> #include <errno.h> #include <string.h> #include <unistd.h> /* from gnokii's include/links/fbus-common.h */ #define FBUS_DEVICE_PHONE 0x00 int test(int fd) { struct sockaddr_pn addr = { .spn_family = AF_PHONET, .spn_dev = FBUS_DEVICE_PHONE }; unsigned char req[] = {0x03, 0x15, 0x01}; /* addr.spn_resource = 0x1b get product name */ char *port = "usbpn0"; unsigned char buf[1024]; ssize_t len; int i; if (setsockopt(fd, SOL_SOCKET, SO_BINDTODEVICE, port, strlen(port))) { perror("setsockopt"); return 1; } addr.spn_resource = 0x1b; if (sendto(fd, &req, sizeof(req), 0, (const struct sockaddr *)&addr, sizeof(addr)) == -1) { perror("sendto"); return 1; } len = recvfrom(fd, buf, sizeof(buf), 0, NULL, NULL); if (len == (ssize_t)-1) { perror("recvfrom"); return 1; } for (i = 0; i < len; i++) printf("%02x ", buf[i]); printf("\n"); return 0; } int main(int argc, char *argv[]) { int fd, error; fd = socket(PF_PHONET, SOCK_DGRAM, 0); if (fd == -1) { perror("socket"); return 1; } error = test(fd); close(fd); return error; }