How to find and connect to remote equipment Symbian translation

zhaozj2021-02-16  50

How to find and connect to remote equipment

When an application is connected to a remote device to apply a service, we need a few steps: first look at whether there is a device that is going to communicate with it. Then look at whether the service needs is available. Finally, the application needs to be connected, and some security measures may also be required.

The following topics will be introduced in turn:

Selecting how the remote device How to query how remote devices queries how services on remote devices are connected to remote device connection and transfer data to apply security measures on external sockets

Selecting a remote device

An application can determine which remote device is the object he communicated by the following method:

· Fixed connection

· Implement storage configuration

· Select by the user

· Program automatic decision

Each of the above may be properly appropriate. In the first two methods, the address of the remote device only needs to be removed from the store. The third method is generally provided in the Bluetooth UI.

The last program automatically selects the remote device, it may be applied in the following cases:

· Provide customizable device selection UI

· Select equipment in some special circumstances, such as "Select the most idle LAN access point"

How to query remote devices

Each Bluetooth device has a unique 48-bit address in its hardware. A basic device query within a range will return zero or several such addresses.

In addition to this address, the Bluetooth device also has a text name display to the user. If you want to display a list of available devices to users, you have to get these names to display.

If the underlying hardware support, addresses and names can also be queried simultaneously. Otherwise, the address of the address must be completed before the name query request is sent.

The generalization sockets RHOSTRESOLver is used to complete the address and device name. In addition, TiNquysockAddr is a dedicated Bluetooth socket address class, which encapsulates the Bluetooth address, query the entry code to provide services and device classes for related queries.

Get the address of the remote device

The following steps are used to query the address of the remote device:

1. Connect to the socket server (RSocketServ), then use RSocketServ :: FindProtocol () to select the protocol used. Since the query of the name and address is supported by the stack of BtlinkManager protocol layer, choose it.

2. Create and initialize a RhostResolver object.

3. Set the TINQUIRYSOCKADDR parameter to query: For the address query, the KhostResinquiry flag needs to be set via TinquiRysockAddr :: SetAction ().

You can then start query via rhostresolver :: getByAddress ().

How to query the service of remote devices

A remote device can have one or more Bluetooth service providers. The wide range of services can be read from the class of the device. This can be used to select a suitable device icon to give the user. The class of this device can be obtained with TinquysockAddr :: MajorclassofDevice () after querying the address.

At a particular environment, the thick-level service findings provided by the device are not satisfied with the selection conditions for the device. In this way, the service discovery request can be used to determine if it is a suitable selection. But only after the required time should be applied because it requires some additional time to request SDP requests for each device. The SDP request is made through the Bluetooth discovery agent API.

How to connect and transfer data with remote devices

Once the equipment and services are determined, you can connect to the remote device and start using it.

Connect to the device through the generalized Symbian OS socket excuses RSocket's Connect () function. Bluetooth sockets can be opened with L2CAP and RFCCOMM protocols. For a L2CAP Bluetooth socket, port (port) is a protocol / service multiplexer (PSM) used to connect; for RFCOMM, the port is a server channel. If these values ​​do not know, you can get it by reading service properties ProtocoldescriptorList. For details, see Using the Bluetooth Services Discovery Agent You can read and write data using the target service expectations through the socket (AT instruction, text, http, ppp, etc.)

Example:

// Assume have a TInquirySockAddr object, addr, with relevant device info // Connect an L2CAP socketRSocket socket; TRequestStatus status; User :: LeaveIfError (socket.Open (socketServ, KBTAddrFamily, KSockSeqPacket, KL2CAP)); User :: LeaveIfError (socket .Connect (addr, status); user :: waitforrequest (status); if (status == kerrnone) {// Write Some Simple Data_Lit8 (KDataTowrite, "01234"); socket.write (kdatatowrite, status); user :: waitforrequest (status);} // close socketsocket.close ();

note:

· For RFCMM and L2CAP protocols, no data can be sent in Connect () and shutdown () calls, otherwise the error will result in additional data.

• RFCOMM uses a stream socket type (KSOCKSTREAM).

· L2CAP uses a sequence package socket type (KSOCKSEQPACKET).

How to apply security measures on an external socket

For an Outgoing Connection, the Bluetooth stack will not be concrete security measures by default. If the remote device needs to be authenticated or encoded, the stack is directly reflected to the application.

Sometimes, the local program also needs to guarantee authentication or encoding. The ioctl khciauthRequestiOctL may be authenticated or the KHCIENCryptiOctL can be authenticated.

Example

The following example will apply IOCTL for the authentication request.

// Assume Have an Opened L2CAP RSocket Object, SocketSocket.ioc (KHCIAUTHREQUESTIOCTL, STATUS, NULL, KSOLBTHCI); User :: WaitforRequest (status); if (status == Kerrnone) {// Success ...

PS: Even in learning, if there is a mistake, please advise.

转载请注明原文地址:https://www.9cbs.com/read-27027.html

New Post(0)