Important: |
---|
This is retired content. This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies. This content may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist. |
This function sets a socket option.
Note: |
---|
This function is actually a Winsock function. However, the information that is presented in it is specific to Bluetooth. |
Syntax
int setsockopt( SOCKET s, int level, int optname, const char FAR* optval, int optlen ); |
Parameters
- s
-
[in] Descriptor identifying a socket. Must be a Bluetooth socket.
- level
-
[in] Level at which the option is defined. Must be SOL_RFCOMM.
- optname
-
[in] Socket option for which the value is to be set. The following table shows possible values for this parameter.
-
Value Description SO_BTH_AUTHENTICATE
On connected socket, triggers authentication. On not connected socket, forces authentication on connection. For incoming connection this means that connection is rejected if authentication cannot be performed.
The optvaland optlenparameters are ignored; however, Winsock implementation on Windows Embedded CE requires optlento be at least 4 and optvalto point to at least an integer datum.
SO_BTH_ENCRYPT
On a connected socket, this command turns encryption on or off. On an unconnected socket, this forces encryption to be on or off on connection. For an incoming connection, this means that the connection is rejected if the encryption cannot be turned on.
optvalis a pointer to intencryption_on; // TRUE or FALSE; optlenis sizeof(int)
On a connected socket, this command will toggle encryption for all sessions sharing the same Baseband connection. You should use it ONLY if you know what you are doing (for example, yours is the only application); otherwise, the link presumed more secure by another application may become unencrypted.
For unconnected sockets, encryption can only be turned ON. (If the encryption flag is set to FALSE, it does not initiate encryption request; however, if encryption is already on, it stays on).
SO_BTH_SET_PIN
This sets or revokes PIN code to use with a connection or socket.
optvalmust be a pointer to initialized BTH_SOCKOPT_SECURITYstructure optlenmust contain sizeof(BTH_SOCKOPT_SECURITY)
SO_BTH_SET_LINK
This sets or revokes link key to use with a connection or peer device.
optvalmust be a pointer to initialized BTH_SOCKOPT_SECURITYstructure; optlenmust contain sizeof(BTH_SOCKOPT_SECURITY)
SO_BTH_SET_MTU
This sets default MTU (maximum transmission unit) for connection negotiation. While allowed for connected socket, it has no effect if the negotiation has already completed. Setting it on listening socket will propagate the value for all incoming connections.
optvalis a pointer to intmtu; optlenis sizeof(int)
SO_BTH_SET_MTU_MAX
This sets maximum MTU for connection negotiation. While allowed for connected socket, it has no effect if the negotiation has already completed. Setting it on listening socket will propagate the value for all incoming connections.
optvalis a pointer to intmax_mtu; optlenis sizeof(int)
SO_BTH_SET_MTU_MIN
This sets minimum MTU for connection negotiation. While allowed for connected socket, it has no effect if the negotiation has already completed. Setting it on listening socket will propagate the value for all incoming connections.
optvalis a pointer to intmin_mtu; optlenis sizeof(int)
SO_BTH_SET_XON_LIM
This sets XON limit. Setting it on listening socket will propagate the value for all incoming connections.
XON limit is only used for peers that do not support credit-based flow control (mandatory in the Bluetooth Core Specification version 1.1). When amount of incoming data received, but not read by an application for a given connection grows past this limit, a flow control command is sent to the peer requiring suspension of transmission.
optvalis a pointer to intxon; optlenis sizeof(int)
SO_BTH_SET_XOFF_LIM
This sets XOFF limit. Setting it on listening socket will propagate the value for all incoming connections.
XOFF limit is only used for peers that do not support credit-based flow control (mandatory in the Bluetooth Core Specification 1.1). If flow has been suspended because of buffer run-up, when amount of incoming data received, but not read by an application for a given connection falls below this limit, a flow control command is sent to the peer allowing continuation of transmission.
optvalis a pointer to intxoff; optlenis sizeof(int)
SO_BTH_SET_SEND_BUFFER
Specifies maximum amount of data that can be buffered inside RFCOMM (this is amount of data before call to send blocks).
optvalis a pointer to intbuffer_size; optlenis sizeof(int)
SO_BTH_SET_RECV_BUFFER
Specifies maximum amount of data that can be buffered for a connection. This buffer size is used to compute number of credits granted to peer device when credit-based flow control is implemented. This specifies the maximum amount of data that can be buffered.
If credit-based flow is not implemented, it is possible to create buffer overruns, because, prior to the Bluetooth Core Specification 1.1, the flow control mechanism does not guarantee adherence to buffer limit (the peer might have already sent more data than can be held before receiving the flow off command. Setting relatively lower limits on XON will make this situation less probable.
optvalis a pointer to intbuffer_size; optlenis sizeof(int)
SO_BTH_SEND_MSC
Sends MSC command. V24 and breaks are as specified in RFCOMM Specification. Only modem signals and breaks can be controlled, RFCOMM reserved fields such as flow control are ignored and should be set to 0.
optvalis a pointer to { intv24; intbreaks; } optlenis 2* sizeof(int)
SO_BTH_SEND_RLS
Sends RLS command. Argument is as specified in RFCOMM Specification.
optvalis a pointer to intrls; optlenis sizeof(int)
SO_BTH_SET_PAGE_TO
Sets the page timeout for the card. The socket does not have to be connected.
optvalis a pointer to unsigned intpage timeout; optlenis sizeof(unsigned int)
SO_BTH_SET_SCAN
Sets the scan mode for the card. The socket does not have to be connected.
optvalis a pointer to unsigned intscan mode; optlenis sizeof(unsigned int)
SO_BTH_SET_COD
Sets the class of the device. The socket does not have to be connected.
optvalis a pointer to unsigned intcod; optlenis sizeof(unsigned int)
SO_BTH_SET_AUTHN_ENABLE
Sets the authentication policy of the device.
optvalis a pointer to unsigned intauthentication enable; optlenis sizeof(unsigned int)
SO_BTH_SET_READ_REMOTE_NAME
Reads the remote name of the device. The socket does not have to be connected.
optvalis a pointer to a BTH_REMOTE_NAMEstructure; optlenis sizeof(BTH_REMOTE_NAME)
SO_BTH_SET_LINK_POLICY
Sets the link policy for an existing baseband connection. The socket must be connected.
optvalis a pointer to unsigned intlink policy; optlenis sizeof(unsigned int)
SO_BTH_ENTER_HOLD_MODE
Places the ACL connection to the specified peer device in HOLD mode.
optvalis a pointer to the BTH_HOLD_MODEstructure; optlenis sizeof(BTH_HOLD_MODE)
SO_BTH_ENTER_SNIFF_MODE
Places the ACL connection to the specified peer device in SNIFF mode.
optvalis a pointer to the BTH_SNIFF_MODEstructure; optlenis sizeof(BTH_SNIFF_MODE)
SO_BTH_EXIT_SNIFF_MODE
Forces the ACL connection to the peer device to leave SNIFF mode.
SO_BTH_ENTER_PARK_MODE
Places the ACL connection to the peer device in PARK mode.
optvalis a pointer to the BTH_PARK_MODEstructure; optlenis sizeof(BTH_PARK_MODE)
SO_BTH_EXIT_PARK_MODE
Forces the ACL connection to the peer device to leave PARK mode.
SO_BTH_GET_MODE
Retrieves the current role for peer Bluetooth device.
- optval
-
[in] Pointer to the buffer in which the value for the requested option is supplied.
- optlen
-
[in] Size of the optvalbuffer.
Return Value
If no error occurs, this function returns zero. If an error occurs, a value of SOCKET_ERROR is returned, and a specific error code can be retrieved by calling WSAGetLastError.
Remarks
RFCOMM supports only one connection for a particular server channel between two devices. If application A on device X is connected to server P on device Y, application B on device X will not be able to connect to the same server on device Y. However, device Y will be able to accept an incoming connection on the same server channel from a different device, as well as an incoming connection from device X to a different server channel.
Socket options can be configured for accepting sockets, connecting sockets, and connected sockets.
When a socket option is set for an accepting socket, it is inherited by the socket that is automatically created by Winsock on incoming connections.
When a socket option is set on a connected socket, it overruns whatever the defaults were imposed by its parent socket.
Some parameters are used during negotiation, such as default, minimum and maximum MTU sizes. These values can be manipulated on connected sockets, but have no effect.
For more information about the setsockoptfunction, see setsockopt (Windows Sockets)in the Winsock reference.
Requirements
Header | winsock2.h, ws2bth.h |
Library | Ws2.lib |
Windows Embedded CE | Windows CE .NET 4.0 and later |
Windows Mobile | Windows Mobile Version 5.0 and later |