pppout.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /*!
  2. * Copyright (C) 2002 by Call Direct Cellular Solutions Pty. Ltd. All rights reserved
  3. * Copyright (C) 2001-2004 by egnite Software GmbH
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions
  7. * are met:
  8. *
  9. * 1. Redistributions of source code must retain the above copyright
  10. * notice, this list of conditions and the following disclaimer.
  11. * 2. Redistributions in binary form must reproduce the above copyright
  12. * notice, this list of conditions and the following disclaimer in the
  13. * documentation and/or other materials provided with the distribution.
  14. * 3. Neither the name of the copyright holders nor the names of
  15. * contributors may be used to endorse or promote products derived
  16. * from this software without specific prior written permission.
  17. *
  18. * THIS SOFTWARE IS PROVIDED BY CALL DIRECT CELLULAR SOLUTIONS AND CONTRIBUTORS
  19. * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  20. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  21. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL CALL DIRECT
  22. * CELLULAR SOLUTIONS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  23. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  24. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  25. * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
  26. * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  27. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
  28. * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  29. * SUCH DAMAGE.
  30. *
  31. * For additional information see http://www.calldirect.com.au/
  32. * For additional information see http://www.ethernut.de/
  33. */
  34. /*!
  35. * \file net/pppout.c
  36. * \brief PPP output functions.
  37. *
  38. * \verbatim
  39. * $Id: pppout.c 5505 2014-01-01 11:15:16Z mifi $
  40. * \endverbatim
  41. */
  42. #include <cfg/os.h>
  43. #include <string.h>
  44. #include <dev/ppp.h>
  45. #include <dev/ahdlc.h>
  46. #include <netinet/in.h>
  47. #include <netinet/if_ppp.h>
  48. #include <net/ppp.h>
  49. #include <sys/types.h>
  50. #include <sys/timer.h>
  51. #ifdef NUTDEBUG
  52. #include <net/netdebug.h>
  53. #endif
  54. /*!
  55. * \addtogroup xgPPP
  56. */
  57. /*@{*/
  58. /*!
  59. * \brief Send PPP frame.
  60. *
  61. * Send a PPP frame of a given type using the specified device.
  62. *
  63. * \param dev Identifies the network device to use.
  64. * \param type Type of this frame.
  65. * \param ha Hardware address of the destination, ignored with PPP.
  66. * \param nb Network buffer structure containing the packet to be sent.
  67. * The structure must have been allocated by a previous
  68. * call NutNetBufAlloc() and will be freed if this function
  69. * returns with an error.
  70. *
  71. * \return 0 on success, -1 in case of any errors.
  72. */
  73. int NutPppOutput(NUTDEVICE * dev, uint16_t type, uint8_t * ha, NETBUF * nb)
  74. {
  75. PPPHDR *ph;
  76. IFNET *nif = dev->dev_icb;
  77. PPPDCB *dcb = dev->dev_dcb;
  78. (void)ha;
  79. /*
  80. * Allocate and set the HDLC header.
  81. */
  82. if (NutNetBufAlloc(nb, NBAF_DATALINK, sizeof(PPPHDR)) == 0)
  83. return -1;
  84. ph = (PPPHDR *) nb->nb_dl.vp;
  85. ph->address = AHDLC_ALLSTATIONS;
  86. ph->control = AHDLC_UI;
  87. ph->prot_type = htons(type);
  88. #ifdef NUTDEBUG
  89. if (__ppp_trf) {
  90. fputs("\nPPP<", __ppp_trs);
  91. NutDumpPpp(__ppp_trs, nb);
  92. }
  93. #elif defined(__IMAGECRAFT__)
  94. /*
  95. * No idea what this is, but ICCAVR fails if this call isn't there.
  96. */
  97. NutSleep(100);
  98. #endif
  99. /*
  100. * Call the physical device output routine.
  101. */
  102. if (nif->if_send && (*nif->if_send) ((((NUTFILE *) (uintptr_t) (dcb->dcb_fd)))->nf_dev, nb) == 0) {
  103. return 0;
  104. }
  105. NutNetBufFree(nb);
  106. return -1;
  107. }
  108. /*@}*/