Initial code commit for Toolkit 1.1.
[silc.git] / lib / silccore / silcpacket.h
1 /*
2
3   silcpacket.h
4
5   Author: Pekka Riikonen <priikone@silcnet.org>
6
7   Copyright (C) 1997 - 2005 Pekka Riikonen
8
9   This program is free software; you can redistribute it and/or modify
10   it under the terms of the GNU General Public License as published by
11   the Free Software Foundation; version 2 of the License.
12
13   This program is distributed in the hope that it will be useful,
14   but WITHOUT ANY WARRANTY; without even the implied warranty of
15   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16   GNU General Public License for more details.
17
18 */
19
20 /****h* silccore/Packet Protocol Interface
21  *
22  * DESCRIPTION
23  *
24  * Implementation of the packet routines for sending and receiving
25  * SILC Packets. These includes the data sending routines and data
26  * reading routines, encrypting and decrypting routines, packet assembling
27  * and packet parsing routines.
28  *
29  ***/
30
31 #ifndef SILCPACKET_H
32 #define SILCPACKET_H
33
34 /* XXX many of these could go to silcpacket_i.h */
35
36 /* Maximum packet length */
37 #define SILC_PACKET_MAX_LEN 0xffff
38
39 /* Maximum length of ID */
40 #define SILC_PACKET_MAX_ID_LEN 28
41
42 /****d* silccore/SilcPacketAPI/SilcPacketType
43  *
44  * NAME
45  *
46  *    typedef SilcUInt8 SilcPacketType;
47  *
48  * DESCRIPTION
49  *
50  *    SILC packet type definition and all the packet types.
51  *
52  * SOURCE
53  */
54 typedef SilcUInt8 SilcPacketType;
55
56 /* SILC Packet types. */
57 #define SILC_PACKET_NONE                 0       /* NULL, never sent */
58 #define SILC_PACKET_DISCONNECT           1       /* Disconnection */
59 #define SILC_PACKET_SUCCESS              2       /* Success */
60 #define SILC_PACKET_FAILURE              3       /* Failure */
61 #define SILC_PACKET_REJECT               4       /* Rejected */
62 #define SILC_PACKET_NOTIFY               5       /* Notify message */
63 #define SILC_PACKET_ERROR                6       /* Error message */
64 #define SILC_PACKET_CHANNEL_MESSAGE      7       /* Message for channel */
65 #define SILC_PACKET_CHANNEL_KEY          8       /* Key of the channel */
66 #define SILC_PACKET_PRIVATE_MESSAGE      9       /* Private message */
67 #define SILC_PACKET_PRIVATE_MESSAGE_KEY  10      /* Private message key*/
68 #define SILC_PACKET_COMMAND              11      /* Command */
69 #define SILC_PACKET_COMMAND_REPLY        12      /* Reply to a command */
70 #define SILC_PACKET_KEY_EXCHANGE         13      /* Start of KE */
71 #define SILC_PACKET_KEY_EXCHANGE_1       14      /* KE1 */
72 #define SILC_PACKET_KEY_EXCHANGE_2       15      /* KE2 */
73 #define SILC_PACKET_CONNECTION_AUTH_REQUEST 16   /* Request of auth meth */
74 #define SILC_PACKET_CONNECTION_AUTH      17      /* Connectinon auth */
75 #define SILC_PACKET_NEW_ID               18      /* Sending new ID */
76 #define SILC_PACKET_NEW_CLIENT           19      /* Client registering */
77 #define SILC_PACKET_NEW_SERVER           20      /* Server registering */
78 #define SILC_PACKET_NEW_CHANNEL          21      /* Channel registering */
79 #define SILC_PACKET_REKEY                22      /* Re-key start */
80 #define SILC_PACKET_REKEY_DONE           23      /* Re-key done */
81 #define SILC_PACKET_HEARTBEAT            24      /* Heartbeat */
82 #define SILC_PACKET_KEY_AGREEMENT        25      /* Key Agreement request */
83 #define SILC_PACKET_RESUME_ROUTER        26      /* Backup router resume */
84 #define SILC_PACKET_FTP                  27      /* File Transfer */
85 #define SILC_PACKET_RESUME_CLIENT        28      /* Client resume */
86
87 #define SILC_PACKET_PRIVATE              200     /* Private range start  */
88 #define SILC_PACKET_MAX                  255     /* RESERVED */
89 /***/
90
91 /****d* silccore/SilcPacketAPI/SilcPacketFlags
92  *
93  * NAME
94  *
95  *    typedef SilcUInt8 SilcPacketFlags;
96  *
97  * DESCRIPTION
98  *
99  *    SILC packet flags type definition and all the packet flags.
100  *
101  * SOURCE
102  */
103 typedef SilcUInt8 SilcPacketFlags;
104
105 /* All defined packet flags */
106 #define SILC_PACKET_FLAG_NONE             0x00    /* No flags */
107 #define SILC_PACKET_FLAG_PRIVMSG_KEY      0x01    /* Private message key */
108 #define SILC_PACKET_FLAG_LIST             0x02    /* Packet is a list */
109 #define SILC_PACKET_FLAG_BROADCAST        0x04    /* Packet is a broadcast */
110 #define SILC_PACKET_FLAG_COMPRESSED       0x08    /* Payload is compressed */
111
112 /* Impelemntation specific flags */
113 #define SILC_PACKET_FLAG_LONG_PAD         0x10    /* Use maximum padding */
114 /***/
115
116 /****s* silccore/SilcPacketAPI/SilcPacketEngine
117  *
118  * NAME
119  *
120  *    typedef struct SilcPacketEngineStruct *SilcPacketEngine;
121  *
122  * DESCRIPTION
123  *
124  *    The packet engine context, allocated by silc_packet_engine_start.
125  *    The engine is destroyed with silc_packet_engine_stop.
126  *
127  ***/
128 typedef struct SilcPacketEngineStruct *SilcPacketEngine;
129
130 /****s* silccore/SilcPacketAPI/SilcPacketStream
131  *
132  * NAME
133  *
134  *    typedef struct SilcPacketStreamStruct *SilcPacketStream;
135  *
136  * DESCRIPTION
137  *
138  *    The packet stream context, allocated by silc_packet_stream_create.
139  *    The stream is destroyed with silc_packet_stream_destroy.
140  *
141  ***/
142 typedef struct SilcPacketStreamStruct *SilcPacketStream;
143
144 /****s* silccore/SilcPacketAPI/SilcPacket
145  *
146  * NAME
147  *
148  *    typedef struct SilcPacketStruct *SilcPacket;
149  *
150  * DESCRIPTION
151  *
152  *    The SilcPacket is returned by the packet engine in the SilcPacketReceive
153  *    callback.  The application can parse the data payload from the
154  *    SilcPacket.  Also packet type, flags, and sender and destination
155  *    IDs are available.  The application must free the packet with the
156  *    silc_packet_free function.
157  *
158  * SOURCE
159  */
160 typedef struct SilcPacketStruct {
161   struct SilcPacketStruct *next;
162   SilcBufferStruct buffer;               /* Packet data payload */
163   unsigned char *src_id;                 /* Source ID */
164   unsigned char *dst_id;                 /* Destination ID */
165   unsigned int src_id_len  : 6;          /* Source ID length */
166   unsigned int src_id_type : 2;          /* Source ID type */
167   unsigned int dst_id_len  : 6;          /* Destination ID length */
168   unsigned int dst_id_type : 2;          /* Destination ID type */
169   SilcPacketType type;                   /* Packet type */
170   SilcPacketFlags flags;                 /* Packet flags */
171 } *SilcPacket;
172 /***/
173
174 /****d* silcutil/SilcPacketAPI/SilcPacketError
175  *
176  * NAME
177  *
178  *    typedef enum { ... } SilcPacketError
179  *
180  * DESCRIPTION
181  *
182  *    Packet errors.  This is returned in the error callback.  If application
183  *    needs the actual lower level stream error, it needs to retrieve it
184  *    from the actual stream.
185  *
186  * SOURCE
187  */
188 typedef enum {
189   SILC_PACKET_ERR_READ,                  /* Error while reading */
190   SILC_PACKET_ERR_WRITE,                 /* Error while writing */
191   SILC_PACKET_ERR_MAC_FAILED,            /* Packet MAC check failed */
192   SILC_PACKET_ERR_DECRYPTION_FAILED,     /* Packet decryption failed */
193   SILC_PACKET_ERR_MALFORMED,             /* Packet is malformed */
194   SILC_PACKET_ERR_NO_MEMORY,             /* System out of memory */
195 } SilcPacketError;
196 /***/
197
198 /****f* silccore/SilcPacketAPI/SilcPacketReceiveCb
199  *
200  * SYNOPSIS
201  *
202  *    typedef void (*SilcPacketReceiveCb)(SilcPacketEngine engine,
203  *                                        SilcPacketStream stream,
204  *                                        SilcPacket packet,
205  *                                        void *callback_context,
206  *                                        void *app_context);
207  *
208  * DESCRIPTION
209  *
210  *    The packet receive callback is called by the packet engine when a new
211  *    SILC Packet has arrived.  The application must free the returned
212  *    SilcPacket with silc_packet_free.  This callback is set in the
213  *    SilcPacketCallbacks structure.
214  *
215  ***/
216 typedef void (*SilcPacketReceiveCb)(SilcPacketEngine engine,
217                                     SilcPacketStream stream,
218                                     SilcPacket packet,
219                                     void *callback_context,
220                                     void *app_context);
221
222 /****f* silccore/SilcPacketAPI/SilcPacketEosCb
223  *
224  * SYNOPSIS
225  *
226  *    typedef void (*SilcPacketEosCb)(SilcPacketEngine engine,
227  *                                    SilcPacketStream stream,
228  *                                    void *callback_context,
229  *                                    void *app_context);
230  *
231  * DESCRIPTION
232  *
233  *    The End Of Stream (EOS) callback, that is called by the packet engine
234  *    when the underlaying stream has ended.  No more data can be sent to
235  *    the stream or read from it.  The `stream' must be destroyed by
236  *    calling the silc_packet_stream_destroy.  This callback is set in the
237  *    SilcPacketCallbacks structure.
238  *
239  ***/
240 typedef void (*SilcPacketEosCb)(SilcPacketEngine engine,
241                                 SilcPacketStream stream,
242                                 void *callback_context,
243                                 void *app_context);
244
245 /****f* silccore/SilcPacketAPI/SilcPacketErrorCb
246  *
247  * SYNOPSIS
248  *
249  *    typedef void (*SilcPacketErrorCb)(SilcPacketEngine engine,
250  *                                      SilcPacketStream stream,
251  *                                      SilcPacketError error,
252  *                                      void *callback_context,
253  *                                      void *app_context);
254  *
255  * DESCRIPTION
256  *
257  *    The error callback that is called by the packet engine if an error
258  *    occurs.  The `error' will indicate the error.  This callback is set
259  *    in the SilcPacketCallbacks structure.
260  *
261  ***/
262 typedef void (*SilcPacketErrorCb)(SilcPacketEngine engine,
263                                   SilcPacketStream stream,
264                                   SilcPacketError error,
265                                   void *callback_context,
266                                   void *app_context);
267
268 /****s* silccore/SilcPacketAPI/SilcPacketStream
269  *
270  * NAME
271  *
272  *    typedef struct SilcPacketStreamStruct *SilcPacketStream;
273  *
274  * DESCRIPTION
275  *
276  *    This structure is sent as argument to the silc_packet_engine_start
277  *    function to set the callback functions for the packet engine.  The
278  *    packet engine will call the callbacks when necessary.  Application
279  *    must always be provided for the packet engine.
280  *
281  * SOURCE
282  */
283 typedef struct {
284   SilcPacketReceiveCb packet_receive;    /* Called when packet is received */
285   SilcPacketEosCb eos;                   /* Called on end of stream */
286   SilcPacketErrorCb error;               /* Called on an error */
287 } SilcPacketCallbacks;
288 /***/
289
290 /* Prototypes */
291
292 /****f* silccore/SilcPacketAPI/silc_packet_engine_start
293  *
294  * SYNOPSIS
295  *
296  *    SilcPacketEngine
297  *    silc_packet_engine_start(SilcSchedule schedule, SilcRng rng, bool router,
298  *                             SilcPacketCallbacks *callbacks,
299  *                             void *callback_context);
300  *
301  * DESCRIPTION
302  *
303  *    Create new packet engine for processing incoming and outgoing packets.
304  *    If `rng' is non-NULL that RNG will be used to create necessary random
305  *    numbers during packet processing.  If NULL, Global RNG will be used.
306  *    If `router' is  TRUE then the application is considered to be router
307  *    server, and certain packets are handled differently.  Client and normal
308  *    server must set it to FALSE.  The `callbacks' is a SilcPacketCallbacks
309  *    structure provided by the caller which includes the callbacks that is
310  *    called when for example packet is received, or end of stream is called
311  *
312  * NOTES
313  *
314  *    The packet engine is thread safe.  Also the `schedule' and `rng' are
315  *    thread safe.  You can use one packet engine in multi threaded
316  *    application.
317  *
318  ***/
319 SilcPacketEngine
320 silc_packet_engine_start(SilcSchedule schedule, SilcRng rng, bool router,
321                          SilcPacketCallbacks *callbacks,
322                          void *callback_context);
323
324 /****f* silccore/SilcPacketAPI/silc_packet_engine_stop
325  *
326  * SYNOPSIS
327  *
328  *    void silc_packet_engine_stop(SilcPacketEngine engine);
329  *
330  * DESCRIPTION
331  *
332  *    Stop the packet engine.  No new packets can be sent or received after
333  *    calling this, and the `engine' will become invalid.
334  *
335  ***/
336 void silc_packet_engine_stop(SilcPacketEngine engine);
337
338 /****f* silccore/SilcPacketAPI/silc_packet_stream_create
339  *
340  * SYNOPSIS
341  *
342  *    SilcPacketStream silc_packet_stream_create(SilcPacketEngine engine,
343  *                                               SilcStream stream);
344  *
345  * DESCRIPTION
346  *
347  *    Create new packet stream and use the `stream' as underlaying stream.
348  *    Usually the `stream' would be a socket stream, but it can be any
349  *    stream.  After this function returns, packets can immediately be
350  *    sent to or received from the stream.
351  *
352  * NOTES
353  *
354  *    SilcPacketStream cannot be used with silc_stream_* routines (such as
355  *    silc_stream_read and silc_stream_write) because of its special nature.
356  *    Use the silc_packet_send and the silc_packet_send_ext to send packets.
357  *    To read packets you will receive the packet receive callback from
358  *    packet engine.  Destroy the stream with silc_packet_stream_destroy.
359  *
360  *    If you need to send only one type of SILC packets, then it is possible
361  *    to create SILC Packet Streamer with silc_packet_streamer_create, which
362  *    can be used with silc_stream_read and silc_stream_write.
363  *
364  *    The SilcPacketStream is not thread safe.  If you share same stream
365  *    with multiple threads concurrency control need to be employed.  It
366  *    is recommended to create new SilcPacketStream for every thread.
367  *
368  ***/
369 SilcPacketStream silc_packet_stream_create(SilcPacketEngine engine,
370                                            SilcStream stream);
371
372 /****f* silccore/SilcPacketAPI/silc_packet_stream_destroy
373  *
374  * SYNOPSIS
375  *
376  *    void silc_packet_stream_destroy(SilcPacketStream stream);
377  *
378  * DESCRIPTION
379  *
380  *    Destroy packet stream and the underlaying stream.  This will also
381  *    send end of stream to the underlaying stream.
382  *
383  ***/
384 void silc_packet_stream_destroy(SilcPacketStream stream);
385
386 /****f* silccore/SilcPacketAPI/silc_packet_streamer_create
387  *
388  * SYNOPSIS
389  *
390  *    SilcStream silc_packet_streamer_create(SilcPacketStream stream,
391  *                                           SilcPacketType packet_type,
392  *                                           SilcPacketFlags packet_flags);
393  *
394  * DESCRIPTION
395  *
396  *    This function can be used to create a SILC Packet Streamer that will
397  *    stream only one type of packet indicated by `packet_type' with packet
398  *    flags `packet_flags'.  This is special purpose function as usually
399  *    multiple different types of packets need to be sent in application.
400  *    There are cases however when creating streamer is simpler and more
401  *    efficient.  Cases such as file transfer stream or other data streams
402  *    that only send and receive one type of packet.  While it would be
403  *    possible to use silc_packet_send function to send packets it is
404  *    more efficient to create the SILC Packet Streamer and use the
405  *    silc_stream_read and silc_stream_write functions.
406  *
407  *    The encryption and decryption keys, and other information will be
408  *    retrieved from the packet stream indicated by `stream', which must be
409  *    created before creating the streamer.
410  *
411  * NOTES
412  *
413  *    The packet type that is assocated with the packet stream `stream' will
414  *    only be available through the returned SilcStream.  That packet type
415  *    will not be delivered to the packet callbacks.  To return to the
416  *    normal operation destroy the streamer silc_packet_streamer_destroy.
417  *
418  ***/
419 SilcStream silc_packet_streamer_create(SilcPacketStream stream,
420                                        SilcPacketType packet_type,
421                                        SilcPacketFlags packet_flags);
422
423 /****f* silccore/SilcPacketAPI/silc_packet_streamer_destroy
424  *
425  * SYNOPSIS
426  *
427  *    void silc_packet_streamer_destroy(SilcStream stream);
428  *
429  * DESCRIPTION
430  *
431  *    Destroys the created packet streamer.  Use this function only for
432  *    stream created with silc_packet_streamer_create.  The packet type
433  *    that was associated with the streamer can be received in the packet
434  *    callbacks after the streamer is destroyed.
435  *
436  ***/
437 void silc_packet_streamer_destroy(SilcStream stream);
438
439 /****f* silccore/SilcPacketAPI/silc_packet_stream_get_stream
440  *
441  * SYNOPSIS
442  *
443  *    SilcStream silc_packet_stream_get_stream(SilcPacketStream stream);
444  *
445  * DESCRIPTION
446  *
447  *    Returns the actual stream that is associated with the packet stream
448  *    `stream'.  The caller must not free the returned stream.  The returned
449  *    stream is the same pointer that was set for silc_packet_stream_create.
450  *    This function couled be used for example when an error callback is
451  *    called by the packet engine to retrieve the actual lower level error
452  *    from the stream.
453  *
454  ***/
455 SilcStream silc_packet_stream_get_stream(SilcPacketStream stream);
456
457 /****f* silccore/SilcPacketAPI/silc_packet_stream_callbacks
458  *
459  * SYNOPSIS
460  *
461  *    void silc_packet_stream_callbacks(SilcPacketStream stream,
462  *                                      SilcPacketCallbacks *callbacks,
463  *                                      void *callback_context);
464  *
465  * DESCRIPTION
466  *
467  *    This is optional function which can be used to set specific callbacks
468  *    for the packet stream indicated by `stream'.  If these are set then
469  *    `callbacks' will be used instead of the ones set for the function
470  *    silc_packet_engine_start.  To reset the normal behaviour call this
471  *    function again with `callbacks' as NULL.  Note that the responsibility
472  *    of handling end of stream, and error conditions moves to the layer
473  *    calling this function since the original callbacks set in the
474  *    silc_packet_engine_start will not be called.
475  *
476  ***/
477 void silc_packet_stream_callbacks(SilcPacketStream stream,
478                                   SilcPacketCallbacks *callbacks,
479                                   void *callback_context);
480
481 /****f* silccore/SilcPacketAPI/silc_packet_stream_ref
482  *
483  * SYNOPSIS
484  *
485  *    void silc_packet_stream_ref(SilcPacketStream stream);
486  *
487  * DESCRIPTION
488  *
489  *    Increase reference counter for the stream indicated by `stream'.  This
490  *    can be used to take a reference for the stream.  To unreference the
491  *    stream call silc_packet_stream_unref function.
492  *
493  ***/
494 void silc_packet_stream_ref(SilcPacketStream stream);
495
496 /****f* silccore/SilcPacketAPI/silc_packet_stream_unref
497  *
498  * SYNOPSIS
499  *
500  *    void silc_packet_stream_unref(SilcPacketStream stream);
501  *
502  * DESCRIPTION
503  *
504  *    Decrease reference counter for the stream indicated by `stream'.  If
505  *    the counter hits zero the stream will be destroyed automatically.
506  *
507  ***/
508 void silc_packet_stream_unref(SilcPacketStream stream);
509
510 /****f* silccore/SilcPacketAPI/silc_packet_set_context
511  *
512  * SYNOPSIS
513  *
514  *    void silc_packet_set_context(SilcPacketStream stream, void *app_context);
515  *
516  * DESCRIPTION
517  *
518  *    Set an application specific context to the stream.  The context will
519  *    be delivered to all callback functions, and it can be retrieved by
520  *    calling silc_packet_get_context function as well.  Note that this is
521  *    separate packet stream specific context, and not the same as
522  *    `callback_context' in silc_packet_engine_start.  Both will be delivered
523  *    to the callbacks.
524  *
525  ***/
526 void silc_packet_set_context(SilcPacketStream stream, void *app_context);
527
528 /****f* silccore/SilcPacketAPI/silc_packet_get_context
529  *
530  * SYNOPSIS
531  *
532  *    void *silc_packet_get_context(SilcPacketStream stream);
533  *
534  * DESCRIPTION
535  *
536  *    Returns the current set application context, or NULL if none is set.
537  *
538  ***/
539 void *silc_packet_get_context(SilcPacketStream stream);
540
541 /****f* silccore/SilcPacketAPI/silc_packet_set_ciphers
542  *
543  * SYNOPSIS
544  *
545  *    void silc_packet_set_ciphers(SilcPacketStream stream, SilcCipher send,
546  *                                 SilcCipher receive);
547  *
548  * DESCRIPTION
549  *
550  *    Set ciphers to be used to encrypt sent packets, and decrypt received
551  *    packets.  This can be called multiple times to change the ciphers.
552  *    In this case if old cipher is set it will be freed.  If ciphers are
553  *    not set packets will not be encrypted or decrypted.
554  *
555  ***/
556 void silc_packet_set_ciphers(SilcPacketStream stream, SilcCipher send,
557                              SilcCipher receive);
558
559 /****f* silccore/SilcPacketAPI/silc_packet_get_ciphers
560  *
561  * SYNOPSIS
562  *
563  *    bool silc_packet_get_ciphers(SilcPacketStream stream, SilcCipher *send,
564  *                                 SilcCipher *receive);
565  *
566  * DESCRIPTION
567  *
568  *    Returns the pointers of current ciphers from the `stream'.  Returns
569  *    FALSE if ciphers are not set.
570  *
571  ***/
572 bool silc_packet_get_ciphers(SilcPacketStream stream, SilcCipher *send,
573                              SilcCipher *receive);
574
575 /****f* silccore/SilcPacketAPI/silc_packet_set_hmacs
576  *
577  * SYNOPSIS
578  *
579  *    void silc_packet_set_hmacs(SilcPacketStream stream, SilcHmac send,
580  *                               SilcHmac receive);
581  *
582  * DESCRIPTION
583  *
584  *    Set HMACs to be used to create MACs for sent packets and to check
585  *    MAC for received packets.  This can be called multiple times to change
586  *    the HMACs.  In this case if old HMAC is set it will be freed.  If
587  *    HMACs are not set MACs are not generated or verified for packets.
588  *
589  ***/
590 void silc_packet_set_hmacs(SilcPacketStream stream, SilcHmac send,
591                            SilcHmac receive);
592
593 /****f* silccore/SilcPacketAPI/silc_packet_get_hmacs
594  *
595  * SYNOPSIS
596  *
597  *    bool silc_packet_get_hmacs(SilcPacketStream stream, SilcHmac *send,
598  *                               SilcHmac *receive);
599  *
600  * DESCRIPTION
601  *
602  *    Returns the pointers of current HMACs from the `stream'.  Returns
603  *    FALSE if HMACs are not set.
604  *
605  ***/
606 bool silc_packet_get_hmacs(SilcPacketStream stream, SilcHmac *send,
607                            SilcHmac *receive);
608
609 /****f* silccore/SilcPacketAPI/silc_packet_set_ids
610  *
611  * SYNOPSIS
612  *
613  *    bool silc_packet_set_ids(SilcPacketStream stream,
614  *                             SilcIdType src_id_type, const void *src_id
615  *                             SilcIdType dst_id_type, const void *dst_id);
616  *
617  * DESCRIPTION
618  *
619  *    Set the source ID and destinaion ID to be used when sending packets to
620  *    this packet stream.  The IDs to be used for a packet stream can be
621  *    overridden when sending packets.  However, if the IDs do not ever change
622  *    for the packet stream it is recommended they are set using this function.
623  *    In this case they can be omitted when sending packets to the stream.
624  *    It is also possible to set only source or destination ID.
625  *
626  ***/
627 bool silc_packet_set_ids(SilcPacketStream stream,
628                          SilcIdType src_id_type, const void *src_id,
629                          SilcIdType dst_id_type, const void *dst_id);
630
631 /****f* silccore/SilcPacketAPI/silc_packet_send
632  *
633  * SYNOPSIS
634  *
635  *    bool silc_packet_send(SilcPacketStream stream,
636  *                          SilcPacketType type, SilcPacketFlags flags,
637  *                          const unsigned char *data, SilcUInt32 data_len);
638  *
639  * DESCRIPTION
640  *
641  *    Send `data' of length of `data_len' to the packet stream indicated by
642  *    `stream'.  If ciphers and HMACs were set using silc_packet_set_ciphers
643  *    and silc_packet_set_hmacs the packet will be encrypted and MAC will be
644  *    generated for it.  If silc_packet_set_ids was used to set source and
645  *    destination ID for the packet stream those IDs are used in the
646  *    packet.  If IDs have not been set and they need to be provided then
647  *    silc_packet_send_ext function should be used.  Otherwise, the packet
648  *    will not have IDs set at all.
649  *
650  ***/
651 bool silc_packet_send(SilcPacketStream stream,
652                       SilcPacketType type, SilcPacketFlags flags,
653                       const unsigned char *data, SilcUInt32 data_len);
654
655 /****f* silccore/SilcPacketAPI/silc_packet_send_ext
656  *
657  * SYNOPSIS
658  *
659  *    bool
660  *    silc_packet_send_ext(SilcPacketStream stream,
661  *                         SilcPacketType type, SilcPacketFlags flags,
662  *                         SilcIdType src_id_type, void *srd_id,
663  *                         SilcIdType dst_id_type, void *dst_id,
664  *                         const unsigned char *data, SilcUInt32 data_len,
665  *                         SilcCipher cipher, SilcHmac hmac);
666  *
667  * DESCRIPTION
668  *
669  *    This function can be used to specificly set different parameters of
670  *    the SILC packet to be sent to the stream indicated by `stream'.  This
671  *    function can be used to set specific IDs, cipher and HMAC to be used
672  *    in packet creation. If `truelen' is provided that value is put to the
673  *    SILC packet's truelen field, if it is zero the routine will calculate
674  *    the truelen field for the packet.  If `padlen' is provided that value
675  *    will be the length of the padding for the packet, if zero the routine
676  *    will calculate necessary amount of padding for the packet.  This
677  *    function can be used when specific ciphers, HMACs and IDs has not been
678  *    set for the stream, or setting them for the stream is not suitable.
679  *
680  ***/
681 bool silc_packet_send_ext(SilcPacketStream stream,
682                           SilcPacketType type, SilcPacketFlags flags,
683                           SilcIdType src_id_type, void *src_id,
684                           SilcIdType dst_id_type, void *dst_id,
685                           const unsigned char *data, SilcUInt32 data_len,
686                           SilcCipher cipher, SilcHmac hmac);
687
688 /****f* silccore/SilcPacketAPI/silc_packet_free
689  *
690  * SYNOPSIS
691  *
692  *    void silc_packet_free(SilcPacketEngine engine, SilcPacket packet);
693  *
694  * DESCRIPTION
695  *
696  *    This function is used to free the SilcPacket pointer that application
697  *    receives in the SilcPacketReceive callback.  Application must free
698  *    the packet.
699  *
700  ***/
701 void silc_packet_free(SilcPacketEngine engine, SilcPacket packet);
702
703 #endif /* SILCPACKET_H */