Home | History | Annotate | Download | only in wifilogd
      1 /*
      2  * Copyright (C) 2016 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 #ifndef PROTOCOL_H_
     18 #define PROTOCOL_H_
     19 
     20 #include <cstdint>
     21 
     22 #include "cutils/sockets.h"
     23 
     24 namespace android {
     25 namespace wifilogd {
     26 namespace protocol {
     27 
     28 constexpr char kServiceSocketName[] = "wifilog";
     29 constexpr char kServiceSocketPath[] = ANDROID_SOCKET_DIR "/wifilog";
     30 
     31 // SOCK_DGRAM require a contiguous memory allocation [1]. Limit the message
     32 // size to one normal page, to maximize reliability. (This size isn't a
     33 // significant limitation as most messages will be much smaller. We don't
     34 // want to go much smaller, though, as packet-fate blobs may be in the
     35 // neighborhood of 2KB.)
     36 //
     37 // [1] http://stackoverflow.com/a/4822037
     38 constexpr size_t kMaxMessageSize = 4096;
     39 
     40 enum class Opcode : uint16_t {
     41   kWriteAsciiMessage,
     42   kDumpBuffers = 0x20,
     43 };
     44 
     45 enum class MessageSeverity : uint8_t {
     46   kError,
     47   kWarning,
     48   kInformational,
     49   kTrace,
     50   kDump,
     51 };
     52 
     53 struct Command {
     54   Command& set_opcode(Opcode new_opcode) {
     55     opcode = new_opcode;
     56     return *this;
     57   }
     58 
     59   Command& set_payload_len(uint16_t new_payload_len) {
     60     payload_len = new_payload_len;
     61     return *this;
     62   }
     63 
     64   uint64_t src_boottime_nsec;  // For latency measurement.
     65   // For drop detection. Sequence numbers are meaningful only within
     66   // the context of a single tag. (This is to minimize synchronization
     67   // requirements for multi-threaded clients.)
     68   uint16_t sequence_num;
     69   Opcode opcode;
     70   uint16_t payload_len;
     71   uint16_t reserved;  // Must be zero.
     72   // Payload follows, with content depending on |opcode|.
     73 };
     74 
     75 struct AsciiMessage {  // Old-style log messages.
     76   AsciiMessage& set_data_len(uint16_t new_data_len) {
     77     data_len = new_data_len;
     78     return *this;
     79   }
     80 
     81   AsciiMessage& set_tag_len(uint8_t new_tag_len) {
     82     tag_len = new_tag_len;
     83     return *this;
     84   }
     85 
     86   AsciiMessage& set_severity(MessageSeverity new_severity) {
     87     severity = new_severity;
     88     return *this;
     89   }
     90 
     91   uint16_t data_len;
     92   uint8_t tag_len;
     93   MessageSeverity severity;
     94   // Payload follows.
     95   // uint8_t tag[tag_len];
     96   // uint8_t data[data_len];
     97 };
     98 
     99 }  // namespace protocol
    100 }  // namespace wifilogd
    101 }  // namespace android
    102 
    103 #endif  // PROTOCOL_H_
    104