13d73f617610de09a68243852c91a2fffcabc367cArman Uguray//
23d73f617610de09a68243852c91a2fffcabc367cArman Uguray//  Copyright (C) 2015 Google, Inc.
33d73f617610de09a68243852c91a2fffcabc367cArman Uguray//
43d73f617610de09a68243852c91a2fffcabc367cArman Uguray//  Licensed under the Apache License, Version 2.0 (the "License");
53d73f617610de09a68243852c91a2fffcabc367cArman Uguray//  you may not use this file except in compliance with the License.
63d73f617610de09a68243852c91a2fffcabc367cArman Uguray//  You may obtain a copy of the License at:
73d73f617610de09a68243852c91a2fffcabc367cArman Uguray//
83d73f617610de09a68243852c91a2fffcabc367cArman Uguray//  http://www.apache.org/licenses/LICENSE-2.0
93d73f617610de09a68243852c91a2fffcabc367cArman Uguray//
103d73f617610de09a68243852c91a2fffcabc367cArman Uguray//  Unless required by applicable law or agreed to in writing, software
113d73f617610de09a68243852c91a2fffcabc367cArman Uguray//  distributed under the License is distributed on an "AS IS" BASIS,
123d73f617610de09a68243852c91a2fffcabc367cArman Uguray//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
133d73f617610de09a68243852c91a2fffcabc367cArman Uguray//  See the License for the specific language governing permissions and
143d73f617610de09a68243852c91a2fffcabc367cArman Uguray//  limitations under the License.
153d73f617610de09a68243852c91a2fffcabc367cArman Uguray//
163d73f617610de09a68243852c91a2fffcabc367cArman Uguray
173d73f617610de09a68243852c91a2fffcabc367cArman Uguray#pragma once
183d73f617610de09a68243852c91a2fffcabc367cArman Uguray
193d73f617610de09a68243852c91a2fffcabc367cArman Uguray#include <base/macros.h>
203d73f617610de09a68243852c91a2fffcabc367cArman Uguray#include <base/time/time.h>
213d73f617610de09a68243852c91a2fffcabc367cArman Uguray
223d73f617610de09a68243852c91a2fffcabc367cArman Uguraynamespace bluetooth {
233d73f617610de09a68243852c91a2fffcabc367cArman Uguray
243d73f617610de09a68243852c91a2fffcabc367cArman Uguray// AdvertiseSettings provides a way to adjust advertising preferences for each
253d73f617610de09a68243852c91a2fffcabc367cArman Uguray// Bluetooth LE advertisement instance. This is the native equivalent of the
263d73f617610de09a68243852c91a2fffcabc367cArman Uguray// Android framework class defined in
273d73f617610de09a68243852c91a2fffcabc367cArman Uguray// frameworks/base/core/java/android/bluetooth/le/AdvertiseSettings.java
283d73f617610de09a68243852c91a2fffcabc367cArman Ugurayclass AdvertiseSettings {
293d73f617610de09a68243852c91a2fffcabc367cArman Uguray public:
303d73f617610de09a68243852c91a2fffcabc367cArman Uguray  // Advertising mode describes power consumption mode used for advertising.
313d73f617610de09a68243852c91a2fffcabc367cArman Uguray  enum Mode {
323d73f617610de09a68243852c91a2fffcabc367cArman Uguray    // Perform Bluetooth LE advertising in low power mode. This is the default
333d73f617610de09a68243852c91a2fffcabc367cArman Uguray    // and preferred advertising mode as it consumes the least power.
343d73f617610de09a68243852c91a2fffcabc367cArman Uguray    MODE_LOW_POWER = 0x00,
353d73f617610de09a68243852c91a2fffcabc367cArman Uguray
363d73f617610de09a68243852c91a2fffcabc367cArman Uguray    // Perform Bluetooth LE advertising in balanced power mode. This is balanced
373d73f617610de09a68243852c91a2fffcabc367cArman Uguray    // between advertising frequency and power consumption.
383d73f617610de09a68243852c91a2fffcabc367cArman Uguray    MODE_BALANCED = 0x01,
393d73f617610de09a68243852c91a2fffcabc367cArman Uguray
403d73f617610de09a68243852c91a2fffcabc367cArman Uguray    // Perform Bluetooth LE advertising in low latency, high power mode. This
413d73f617610de09a68243852c91a2fffcabc367cArman Uguray    // has the highest power consumption and should not be used for continuous
423d73f617610de09a68243852c91a2fffcabc367cArman Uguray    // background advertising.
433d73f617610de09a68243852c91a2fffcabc367cArman Uguray    MODE_LOW_LATENCY = 0x02,
443d73f617610de09a68243852c91a2fffcabc367cArman Uguray  };
453d73f617610de09a68243852c91a2fffcabc367cArman Uguray
463d73f617610de09a68243852c91a2fffcabc367cArman Uguray  // Levels that can be set for advertising transmission power.
473d73f617610de09a68243852c91a2fffcabc367cArman Uguray  enum TxPowerLevel {
483d73f617610de09a68243852c91a2fffcabc367cArman Uguray    // Advertise using the lowest transmission (TX) power level. Low
493d73f617610de09a68243852c91a2fffcabc367cArman Uguray    // transmission power can be used to restrict the visibility range of
503d73f617610de09a68243852c91a2fffcabc367cArman Uguray    // advertising packets.
513d73f617610de09a68243852c91a2fffcabc367cArman Uguray    TX_POWER_LEVEL_ULTRA_LOW = 0x00,
523d73f617610de09a68243852c91a2fffcabc367cArman Uguray
533d73f617610de09a68243852c91a2fffcabc367cArman Uguray    // Advertise using low TX power level.
543d73f617610de09a68243852c91a2fffcabc367cArman Uguray    TX_POWER_LEVEL_LOW = 0x01,
553d73f617610de09a68243852c91a2fffcabc367cArman Uguray
563d73f617610de09a68243852c91a2fffcabc367cArman Uguray    // Advertise using medium TX power level.
573d73f617610de09a68243852c91a2fffcabc367cArman Uguray    TX_POWER_LEVEL_MEDIUM = 0x02,
583d73f617610de09a68243852c91a2fffcabc367cArman Uguray
593d73f617610de09a68243852c91a2fffcabc367cArman Uguray    // Advertise using high TX power level. This corresponds to largest
603d73f617610de09a68243852c91a2fffcabc367cArman Uguray    // visibility range of the advertising packet.
613d73f617610de09a68243852c91a2fffcabc367cArman Uguray    TX_POWER_LEVEL_HIGH = 0x03,
623d73f617610de09a68243852c91a2fffcabc367cArman Uguray  };
633d73f617610de09a68243852c91a2fffcabc367cArman Uguray
643d73f617610de09a68243852c91a2fffcabc367cArman Uguray  AdvertiseSettings(Mode mode,
653d73f617610de09a68243852c91a2fffcabc367cArman Uguray                    base::TimeDelta timeout,
663d73f617610de09a68243852c91a2fffcabc367cArman Uguray                    TxPowerLevel tx_power_level,
673d73f617610de09a68243852c91a2fffcabc367cArman Uguray                    bool connectable);
683d73f617610de09a68243852c91a2fffcabc367cArman Uguray
693d73f617610de09a68243852c91a2fffcabc367cArman Uguray  // The default constructor sets all fields to defaults:
703d73f617610de09a68243852c91a2fffcabc367cArman Uguray  //   mode: MODE_LOW_POWER
713d73f617610de09a68243852c91a2fffcabc367cArman Uguray  //   TX power level: TX_POWER_LEVEL_MEDIUM
723d73f617610de09a68243852c91a2fffcabc367cArman Uguray  //   connectable: true
733d73f617610de09a68243852c91a2fffcabc367cArman Uguray  AdvertiseSettings();
743d73f617610de09a68243852c91a2fffcabc367cArman Uguray  ~AdvertiseSettings() = default;
753d73f617610de09a68243852c91a2fffcabc367cArman Uguray
763d73f617610de09a68243852c91a2fffcabc367cArman Uguray  // Returns the advertise mode.
773d73f617610de09a68243852c91a2fffcabc367cArman Uguray  Mode mode() const { return mode_; }
783d73f617610de09a68243852c91a2fffcabc367cArman Uguray
793d73f617610de09a68243852c91a2fffcabc367cArman Uguray  // Returns the advertising time limit in milliseconds.
803d73f617610de09a68243852c91a2fffcabc367cArman Uguray  const base::TimeDelta& timeout() const { return timeout_; }
813d73f617610de09a68243852c91a2fffcabc367cArman Uguray
823d73f617610de09a68243852c91a2fffcabc367cArman Uguray  // Returns the TX power level for advertising.
833d73f617610de09a68243852c91a2fffcabc367cArman Uguray  TxPowerLevel tx_power_level() const { return tx_power_level_; }
843d73f617610de09a68243852c91a2fffcabc367cArman Uguray
853d73f617610de09a68243852c91a2fffcabc367cArman Uguray  // Returns whether the advertisement will indicate connectable.
863d73f617610de09a68243852c91a2fffcabc367cArman Uguray  bool connectable() const { return connectable_; }
873d73f617610de09a68243852c91a2fffcabc367cArman Uguray
883d73f617610de09a68243852c91a2fffcabc367cArman Uguray  // Comparison operator.
893d73f617610de09a68243852c91a2fffcabc367cArman Uguray  bool operator==(const AdvertiseSettings& rhs) const;
903d73f617610de09a68243852c91a2fffcabc367cArman Uguray
913d73f617610de09a68243852c91a2fffcabc367cArman Uguray private:
923d73f617610de09a68243852c91a2fffcabc367cArman Uguray  Mode mode_;
933d73f617610de09a68243852c91a2fffcabc367cArman Uguray  base::TimeDelta timeout_;
943d73f617610de09a68243852c91a2fffcabc367cArman Uguray  TxPowerLevel tx_power_level_;
953d73f617610de09a68243852c91a2fffcabc367cArman Uguray  bool connectable_;
963d73f617610de09a68243852c91a2fffcabc367cArman Uguray};
973d73f617610de09a68243852c91a2fffcabc367cArman Uguray
983d73f617610de09a68243852c91a2fffcabc367cArman Uguray}  // namespace bluetooth
99