From owner-freebsd-usb@freebsd.org Thu Oct 3 10:42:18 2019 Return-Path: Delivered-To: freebsd-usb@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 7FF1E130D95 for ; Thu, 3 Oct 2019 10:42:18 +0000 (UTC) (envelope-from hps@selasky.org) Received: from mail.turbocat.net (turbocat.net [IPv6:2a01:4f8:c17:6c4b::2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 46kV2146s8z3RG6 for ; Thu, 3 Oct 2019 10:42:17 +0000 (UTC) (envelope-from hps@selasky.org) Received: from hps2016.home.selasky.org (unknown [62.141.129.235]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by mail.turbocat.net (Postfix) with ESMTPSA id BBB142602CD; Thu, 3 Oct 2019 12:42:13 +0200 (CEST) Subject: Re: USB serial ports by serial number To: "O'Connor, Daniel" Cc: Oleksandr Rybalko , freebsd-usb@freebsd.org References: <40CAFE90-B8F6-4A9B-A6D0-671D2DCEED52@dons.net.au> <1f0a3207-89fd-0ddb-6049-91f114381386@selasky.org> <366762AE-757E-4EB4-9A51-8B513FE7BC42@dons.net.au> <138601da-b6f9-f791-c6ef-ce54a4ae60e6@selasky.org> From: Hans Petter Selasky Message-ID: <7f1aac2b-8184-e404-014b-543505e4ffab@selasky.org> Date: Thu, 3 Oct 2019 12:40:47 +0200 User-Agent: Mozilla/5.0 (X11; FreeBSD amd64; rv:68.0) Gecko/20100101 Thunderbird/68.1.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Rspamd-Queue-Id: 46kV2146s8z3RG6 X-Spamd-Bar: ---- Authentication-Results: mx1.freebsd.org; dkim=none; dmarc=none; spf=pass (mx1.freebsd.org: domain of hps@selasky.org designates 2a01:4f8:c17:6c4b::2 as permitted sender) smtp.mailfrom=hps@selasky.org X-Spamd-Result: default: False [-4.89 / 15.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; NEURAL_HAM_MEDIUM(-1.00)[-1.000,0]; RCPT_COUNT_THREE(0.00)[3]; TO_DN_SOME(0.00)[]; R_SPF_ALLOW(-0.20)[+a:mail.turbocat.net:c]; FROM_HAS_DN(0.00)[]; MIME_GOOD(-0.10)[text/plain]; DMARC_NA(0.00)[selasky.org]; NEURAL_HAM_LONG(-1.00)[-1.000,0]; TO_MATCH_ENVRCPT_SOME(0.00)[]; IP_SCORE(-2.59)[ip: (-9.11), ipnet: 2a01:4f8::/29(-2.04), asn: 24940(-1.80), country: DE(-0.01)]; FROM_EQ_ENVFROM(0.00)[]; R_DKIM_NA(0.00)[]; MIME_TRACE(0.00)[0:+]; ASN(0.00)[asn:24940, ipnet:2a01:4f8::/29, country:DE]; MID_RHS_MATCH_FROM(0.00)[]; RCVD_TLS_ALL(0.00)[]; RCVD_COUNT_TWO(0.00)[2] X-BeenThere: freebsd-usb@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FreeBSD support for USB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 03 Oct 2019 10:42:18 -0000 On 2019-10-03 10:13, O'Connor, Daniel wrote: > > >> On 3 Oct 2019, at 17:41, Hans Petter Selasky wrote: >> >> On 2019-10-03 09:37, O'Connor, Daniel wrote: >>>> On 3 Oct 2019, at 17:01, Hans Petter Selasky wrote: >>>> On 2019-10-03 08:56, O'Connor, Daniel wrote: >>>>> Most of USB-serial devices have "very stable" serial number:) >>>>> more than 50% have S/N "0123456789". >>>> >>>> It is also allowed to have no serial number. >>> Yes, that's why I match sernum to '.+' to skip those. >>>> Maybe some kind of "lstty" would do. >>>> >>>> -l - list all devices >>>> -s - match by serial >>>> -v - match by vendor >>>> -p - match by product >>>> -i - match by interface ID >>>> -t - type [USB/PCI] >>>> >>>> which simply output the tty number you need. Could be an API we could add to libusb. >>> The problem is you can't modify some program to call a new API a lot of the time but it is usually trivial to change which serial port it's configured to use. >> >> You don't need to change any program: >> >> cu /dev/cuaU`lstty -s SERIAL` > > That doesn't work in a lot of cases, eg serial port is in some other configuration file. > > Even in rc.conf it would be tricky since that file is read so often. > How about that we build the cuaX unit number by the location, and have a sysctl for that? unit = 0; while (hubdepth--) { unit *= numports; unit += portno - 1; } unit *= maxifaces; unit += device_get_unit(x); Typically this should fit into a 32-bit integer, but we could also use a 64-bit integer. --HPS