コンテンツにスキップ

Matt socket

header-jamqtt_socket.h

Classes

Name
struct _MqttTls
struct _MqttNet

Types

Name
typedef int()(struct _MqttClient client) MqttTlsCb
typedef int()(void context, const char *host, word16 port, int timeout_ms) MqttNetConnectCb
typedef int()(void context, const byte *buf, int buf_len, int timeout_ms) MqttNetWriteCb
typedef int()(void context, byte *buf, int buf_len, int timeout_ms) MqttNetReadCb
typedef int()(void context, byte *buf, int buf_len, int timeout_ms) MqttNetPeekCb
typedef int()(void context) MqttNetDisconnectCb
typedef struct _MqttTls**
typedef struct _MqttNet**

Functions

Name
WOLFMQTT_LOCAL int **MqttSocket_Init * net)
WOLFMQTT_LOCAL int **MqttSocket_Write * buf, int buf_len, int timeout_ms)
WOLFMQTT_LOCAL int **MqttSocket_Read * buf, int buf_len, int timeout_ms)
WOLFMQTT_LOCAL int **MqttSocket_Peek * buf, int buf_len, int timeout_ms)
WOLFMQTT_LOCAL int **MqttSocket_Connect cb)
WOLFMQTT_LOCAL int MqttSocket_Disconnect(struct _MqttClient * client)
WOLFMQTT_API int MqttSocket_TlsSocketReceive(WOLFSSL * ssl, char * buf, int sz, void * ptr)
WOLFMQTT_API int MqttSocket_TlsSocketSend(WOLFSSL * ssl, char * buf, int sz, void * ptr)

Attributes

Name
C

Types Documentation

typedef MqttTlsCb

typedef int(* MqttTlsCb) (struct _MqttClient *client);

typedef MqttNetConnectCb

typedef int(* MqttNetConnectCb) (void *context, const char *host, word16 port, int timeout_ms);

typedef MqttNetWriteCb

typedef int(* MqttNetWriteCb) (void *context, const byte *buf, int buf_len, int timeout_ms);

typedef MqttNetReadCb

typedef int(* MqttNetReadCb) (void *context, byte *buf, int buf_len, int timeout_ms);

typedef MqttNetPeekCb

typedef int(* MqttNetPeekCb) (void *context, byte *buf, int buf_len, int timeout_ms);

typedef MqttNetDisconnectCb

typedef int(* MqttNetDisconnectCb) (void *context);

typedef MqttTls

typedef struct _MqttTls MqttTls;

typedef MqttNet

typedef struct _MqttNet MqttNet;

Functions Documentation

function MqttSocket_Init

WOLFMQTT_LOCAL int MqttSocket_Init(
    struct _MqttClient * client,
    MqttNet * net
)

function MqttSocket_Write

WOLFMQTT_LOCAL int MqttSocket_Write(
    struct _MqttClient * client,
    const byte * buf,
    int buf_len,
    int timeout_ms
)

function MqttSocket_Read

WOLFMQTT_LOCAL int MqttSocket_Read(
    struct _MqttClient * client,
    byte * buf,
    int buf_len,
    int timeout_ms
)

function MqttSocket_Peek

WOLFMQTT_LOCAL int MqttSocket_Peek(
    struct _MqttClient * client,
    byte * buf,
    int buf_len,
    int timeout_ms
)

function MqttSocket_Connect

WOLFMQTT_LOCAL int MqttSocket_Connect(
    struct _MqttClient * client,
    const char * host,
    word16 port,
    int timeout_ms,
    int use_tls,
    MqttTlsCb cb
)

function MqttSocket_Disconnect

WOLFMQTT_LOCAL int MqttSocket_Disconnect(
    struct _MqttClient * client
)

function MqttSocket_TlsSocketReceive

WOLFMQTT_API int MqttSocket_TlsSocketReceive(
    WOLFSSL * ssl,
    char * buf,
    int sz,
    void * ptr
)

function MqttSocket_TlsSocketSend

WOLFMQTT_API int MqttSocket_TlsSocketSend(
    WOLFSSL * ssl,
    char * buf,
    int sz,
    void * ptr
)

Attributes Documentation

variable C

C {
#endif

#include "wolfmqttmqtt_types.h"
#ifdef ENABLE_MQTT_TLS
    #ifndef WOLF_TLS_DHKEY_BITS_MIN 
        #ifdef WOLFSSL_MAX_STRENGTH
            #define WOLF_TLS_DHKEY_BITS_MIN 2048
        #else
            #define WOLF_TLS_DHKEY_BITS_MIN 1024
        #endif
    #endif
#endif


#define MQTT_DEFAULT_PORT   1883
#define MQTT_SECURE_PORT    8883


struct _MqttClient;

Source code

/* mqtt_socket.h
 *
 * Copyright (C) 2006-2022 wolfSSL Inc.
 *
 * This file is part of wolfMQTT.
 *
 * wolfMQTT is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * wolfMQTT is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
 */

/* Implementation by: David Garske
 * Based on specification for MQTT v3.1.1
 * See http://mqtt.org/documentation for additional MQTT documentation.
 */

#ifndef WOLFMQTT_SOCKET_H
#define WOLFMQTT_SOCKET_H

#ifdef __cplusplus
    extern "C" {
#endif

#include "wolfmqttmqtt_types.h"
#ifdef ENABLE_MQTT_TLS
    #ifndef WOLF_TLS_DHKEY_BITS_MIN /* allow define to be overridden */
        #ifdef WOLFSSL_MAX_STRENGTH
            #define WOLF_TLS_DHKEY_BITS_MIN 2048
        #else
            #define WOLF_TLS_DHKEY_BITS_MIN 1024
        #endif
    #endif
#endif

/* Default Port Numbers */
#define MQTT_DEFAULT_PORT   1883
#define MQTT_SECURE_PORT    8883


struct _MqttClient;

/* Function callbacks */
typedef int (*MqttTlsCb)(struct _MqttClient* client);

typedef int (*MqttNetConnectCb)(void *context,
    const char* host, word16 port, int timeout_ms);
typedef int (*MqttNetWriteCb)(void *context,
    const byte* buf, int buf_len, int timeout_ms);
typedef int (*MqttNetReadCb)(void *context,
    byte* buf, int buf_len, int timeout_ms);
#ifdef WOLFMQTT_SN
typedef int (*MqttNetPeekCb)(void *context,
    byte* buf, int buf_len, int timeout_ms);
#endif
typedef int (*MqttNetDisconnectCb)(void *context);

/* Structure for Network Security */
#ifdef ENABLE_MQTT_TLS
typedef struct _MqttTls {
    WOLFSSL_CTX         *ctx;
    WOLFSSL             *ssl;
    int                 sockRc;
    int                 timeout_ms;
} MqttTls;
#endif

/* Structure for Network callbacks */
typedef struct _MqttNet {
    void                *context;
    MqttNetConnectCb    connect;
    MqttNetReadCb       read;
    MqttNetWriteCb      write;
    MqttNetDisconnectCb disconnect;
#ifdef WOLFMQTT_SN
    MqttNetPeekCb       peek;
    void                *multi_ctx;
#endif
} MqttNet;


/* MQTT SOCKET APPLICATION INTERFACE */
WOLFMQTT_LOCAL int MqttSocket_Init(struct _MqttClient *client, MqttNet* net);
WOLFMQTT_LOCAL int MqttSocket_Write(struct _MqttClient *client, const byte* buf,
        int buf_len, int timeout_ms);
WOLFMQTT_LOCAL int MqttSocket_Read(struct _MqttClient *client, byte* buf,
        int buf_len, int timeout_ms);
#ifdef WOLFMQTT_SN
WOLFMQTT_LOCAL int MqttSocket_Peek(struct _MqttClient *client, byte* buf,
        int buf_len, int timeout_ms);
#endif
WOLFMQTT_LOCAL int MqttSocket_Connect(struct _MqttClient *client,
        const char* host, word16 port, int timeout_ms, int use_tls,
        MqttTlsCb cb);
WOLFMQTT_LOCAL int MqttSocket_Disconnect(struct _MqttClient *client);

#ifdef ENABLE_MQTT_TLS
/* make these public for cases where user needs to create
 * WOLFSSL_CTX context and WOLFSSL object in the TLS callback */
WOLFMQTT_API int MqttSocket_TlsSocketReceive(WOLFSSL* ssl, char *buf, int sz, void *ptr);
WOLFMQTT_API int MqttSocket_TlsSocketSend(WOLFSSL* ssl, char *buf, int sz, void *ptr);
#endif

#ifdef __cplusplus
    } /* extern "C" */
#endif

#endif /* WOLFMQTT_SOCKET_H */