@@ -1912,6 +1912,92 @@ void GenericGap::on_scan_request_received(
1912
1912
1913
1913
}
1914
1914
1915
+ ble_error_t GenericGap::setScanParameters (const GapScanParameters ¶ms)
1916
+ {
1917
+ use_non_deprecated_scan_api ();
1918
+
1919
+ // FIXME: validate parameters
1920
+ // FIXME: deal with random address rotation
1921
+
1922
+ if (is_extended_advertising_enabled ()) {
1923
+ bool active_scanning[] = {
1924
+ params.get_1m_configuration ().active_scanning ,
1925
+ params.get_coded_configuration ().active_scanning
1926
+ };
1927
+
1928
+ uint16_t scan_interval[] = {
1929
+ params.get_1m_configuration ().interval ,
1930
+ params.get_coded_configuration ().interval
1931
+ };
1932
+
1933
+ uint16_t scan_window[] = {
1934
+ params.get_1m_configuration ().window ,
1935
+ params.get_coded_configuration ().window
1936
+ };
1937
+
1938
+ return _pal_gap.set_extended_scan_parameters (
1939
+ (pal::own_address_type_t ::type) params.get_own_address_type (),
1940
+ (pal::scanning_filter_policy_t ::type) params.get_scanning_filter_policy (),
1941
+ params.get_scanning_phys (),
1942
+ active_scanning,
1943
+ scan_interval,
1944
+ scan_window
1945
+ );
1946
+ } else {
1947
+ GapScanParameters::phy_configuration_t legacy_configuration =
1948
+ params.get_1m_configuration ();
1949
+
1950
+ return _pal_gap.set_scan_parameters (
1951
+ legacy_configuration.active_scanning ,
1952
+ legacy_configuration.interval ,
1953
+ legacy_configuration.window ,
1954
+ (pal::own_address_type_t ::type) params.get_own_address_type (),
1955
+ (pal::scanning_filter_policy_t ::type) params.get_scanning_filter_policy ()
1956
+ );
1957
+ }
1958
+ }
1959
+
1960
+ ble_error_t GenericGap::startScan (
1961
+ scanning_filter_duplicates_t filtering,
1962
+ uint16_t duration,
1963
+ uint16_t period
1964
+ )
1965
+ {
1966
+ use_non_deprecated_scan_api ();
1967
+ // FIXME: deal with random address rotation
1968
+
1969
+ if (is_extended_advertising_enabled ()) {
1970
+ return _pal_gap.extended_scan_enable (
1971
+ /* enable */ true ,
1972
+ (pal::duplicates_filter_t ::type) filtering,
1973
+ duration,
1974
+ period
1975
+ );
1976
+ } else {
1977
+ if (period != 0 ) {
1978
+ return BLE_ERROR_INVALID_PARAM;
1979
+ }
1980
+
1981
+ ble_error_t err = _pal_gap.scan_enable (
1982
+ true ,
1983
+ filtering == SCAN_FILTER_DUPLICATES_DISABLED ? false : true
1984
+ );
1985
+
1986
+ if (err) {
1987
+ return err;
1988
+ }
1989
+
1990
+ _scan_timeout.detach ();
1991
+ if (duration) {
1992
+ _scan_timeout.attach_us (
1993
+ mbed::callback (this , &GenericGap::on_scan_timeout),
1994
+ duration * 10 /* ms */ * 1000 /* us */
1995
+ );
1996
+ }
1997
+
1998
+ return BLE_ERROR_NONE;
1999
+ }
2000
+ }
1915
2001
1916
2002
void GenericGap::use_deprecated_scan_api () const
1917
2003
{
0 commit comments